Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/04/2012, 01:30
direccionderegistro
 
Fecha de Ingreso: abril-2012
Mensajes: 5
Antigüedad: 12 años
Puntos: 0
Pregunta Respuesta: Mostrar en web resultado de consulta javascript a ms access

Esto es como sigue el código del archivo *.js

En esta parte está una función de creación de tabla, que creo que es a la que tengo que llamar desde el script...-----------------------------------------------------

this.outJSON = function(rs) {
var json = "[";
rs.MoveFirst();
while (!rs.eof) {
json += '{';
for (var x = 0; x < rs.Fields.Count; x++) {
json += '"' + rs.Fields(x).Name + '":';
var val = rs.Fields(x).Value;
if (typeof(val) == "string") {
val = val.replace(/\"/g, '"');
val = val.replace(/\'/g, ''');
val = '"' + val + '"';
}
if (typeof(val) == "date") {
val = "new Date(\"" + val + "\")";
}
json += val + ',';
}
json = json.slice(0, json.length - 1);
rs.MoveNext();
json += '},';
}
json = json.slice(0, json.length - 1);
json += ']';
return json;
};

this.outXML = function(rs, options) {
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><recordset>";
rs.MoveFirst();
while (!rs.eof) {
xml += '<record>';
for (var x = 0; x < rs.Fields.Count; x++) {
var val = rs.Fields(x).Value;
if (typeof(val) == "string") {
val = val.replace(/\&/g, '&');
val = val.replace(/\</g, '<');
val = val.replace(/\>/g, '>');
}
else if (typeof(val) == "date" && options.formatDates) {
if (typeof(options.formatDates) == "string") {
val = (new Date((val))).format(options.formatDates);
}
else {
for (var col in options.formatDates) {
if (col == rs.Fields(x).Name) {
val = (new Date((val))).format(options.formatDates[col]);
}
}
}
}
xml += "<" + rs.Fields(x).Name + ">" + val + "</" + rs.Fields(x).Name + ">";
}
xml += '</record>';
rs.MoveNext();
}
xml += '</recordset>';

if (!options.stringOut) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(xml);
xml = xmlDoc;
}
return xml;
};

this.outTable = function(rs, options) {
var tbl = document.createElement("table");
tbl.cellPadding = 0;
tbl.cellSpacing = 0;
var tbody = document.createElement("tbody");
tbl.appendChild(tbody);
if (options.id) {
tbl.id = options.id;
}
if (options.className) {
tbl.className = options.className;
}
rs.MoveFirst();
if (!options.noHeaders) {
var row = document.createElement("tr");
tbody.appendChild(row);
for (var x = 0; x < rs.Fields.Count; x++) {
var hdr = document.createElement("th");
hdr.innerHTML = rs.Fields(x).Name;
row.appendChild(hdr);
}
}
while (!rs.eof) {
var row = document.createElement("tr");
tbody.appendChild(row);
for (var x = 0; x < rs.Fields.Count; x++) {
var val = rs.Fields(x).Value;
if (typeof(val) == "string") {
val = val.replace(/\&/g, '&');
val = val.replace(/\</g, '<');
val = val.replace(/\>/g, '>');
}
else if (typeof(val) == "date" && options.formatDates) {
if (typeof(options.formatDates) == "string") {
val = (new Date((val))).format(options.formatDates);
}
else {
for (var col in options.formatDates) {
if (col == rs.Fields(x).Name) {
val = (new Date((val))).format(options.formatDates[col]);
}
}
}
}
var cell = document.createElement("td");
cell.innerHTML = val;
row.appendChild(cell);
}
rs.MoveNext();
}
if (options.stringOut) { return tbl.outerHTML; }
return tbl;
};

this.kill = function() {
this.conn.close();
delete this;
};

try {
this.conn.open("Provider = " + this.provider + ";Data Source = " + this.dataSource + ";"+this.options.wrkgrpFile+"Persist Security Info = " + this.options.persist, this.options.user, this.options.password);
}
catch (e) {
if (this.options.showErrors) {
alert("Load DB " + e.name + "\n\n" + e.description);
}
}
};

})();

-------------------------------------------------------------------------------

Y este es el código xhtml de la página:

Gracias por vuestra ayuda.


-----------------------------------------------------------------------------------

<HEAD>

<META http-equiv="Content-Type" content="text/html"; charset="ISO-8559-15" />

<TITLE>..:: Centros ::..</TITLE>

<!-- Hoja de estilo -->
<LINK rel="stylesheet" type="text/css" href="CSS1.txt" />
<!-- Indico el script de conexión jsp -->

<SCRIPT type="text/javascript" src="ACCESSdb.js"></SCRIPT>

<!-- Apartado personalizado de la conexión -->

<SCRIPT type="text/javascript">
<!--//--><![CDATA[//><!--
var myDB = new ACCESSdb("Incidencias.mdb", {showErrors:true});
var SQL = "SELECT * from Centros";
var resultSet = myDB.query(SQL);
var rsHTML = myDB.query(SQL, {table: {
id: "myTable",
className: "TT_2",
noHeaders:false,
formatDates: "MM/DD/YYYY",
errorHandler: function(e) {
$("#errorBox").html("" + e.name + ": " + e.description);
}
}
});


//--><!]]>
</SCRIPT>

</HEAD>

Última edición por direccionderegistro; 20/04/2012 a las 12:10 Razón: Legibilidad del mensaje