cGamez010
New Member
- Messages
- 37
- Reaction score
- 0
- Points
- 0
AJAX: unrelated syntax error. Please Help!
hi, i still struggle with xml parsing, it's kinda like quantum physics in my opinion.
here is the xml that i need to parse, there is always an order with leads as children. these leads have various properties, and the last 3 properties have attributes. The php can generate a different order, by service, by supplier and by region by supplying an o querystring variable to the xml generator, with values 0 through 2...
below is the javascript xml parser function.
Previous approach removed.
i am attempting to pass the oarr array to the addorder() function looking as follows:
i do the "multidimentional" arrays ready to be split by delimiter in the dhtml code. the xml parsing code needs to be ready for multiple order and lead tags however. but sofar i haven't even gotten to the addorder() function yet!
Edit:
okay i've edited the function a bit, but now i get of all things a syntax error pointing to the else after checking the return state 0o
here is the updated function
and here is the error which still stands :nuts:
hi, i still struggle with xml parsing, it's kinda like quantum physics in my opinion.
here is the xml that i need to parse, there is always an order with leads as children. these leads have various properties, and the last 3 properties have attributes. The php can generate a different order, by service, by supplier and by region by supplying an o querystring variable to the xml generator, with values 0 through 2...
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<order name="Test Region 7">
<lead>
<id>95</id>
<consumer>Pierre du Toit;pierre@greywacke.co.za</consumer>
<subject>test subject</subject>
<attribs>Test Attribute 1 = Test Value 1<br />Test Attribute 2 = Test Value 3</attribs>
<message>test message</message>
<sent>1</sent>
<created>2009-12-31 17:43:57</created>
<service id="1" name="Test Service 1" cost="20" />
<supplier id="6" name="Test Supplier 1" w3a="http://www.greywacke.co.za/" contact="Pierre du Toit" position="Graphic Design & AJAX" mail="pierre@greywacke.co.za" tel="27729154799" bal="800" />
<region id="8" name="Test Region 7" />
</lead>
</order>
</root>
Previous approach removed.
i am attempting to pass the oarr array to the addorder() function looking as follows:
Code:
Test Region 7,95|Pierre du Toit;pierre@greywacke.co.za|test subject|Test Attribute 1 = Test Value 1<br />Test Attribute 2 = Test Value 3|test message|1|2009-12-31 17:43:57|1;Test Service 1|20|6;Test Supplier 1;|http://www.greywacke.co.za/;Pierre du Toit;Graphic Design & AJAX;pierre@greywacke.co.za;27729154799;800|8;Test Region 7
Edit:
okay i've edited the function a bit, but now i get of all things a syntax error pointing to the else after checking the return state 0o
here is the updated function
Code:
// xml parser
function alertContents() {
// === BEGIN IF 0 ===
if (http_request.readyState == 4) {
// === BEGIN IF 1 ===
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
//alert(this.responseText);
var order = xmldoc.getElementsByTagName("order");
// === BEGIN FOR 0 ===
for (var o = 0; o < order.length; o++) {
var r = 0;
var olen = parseInt(order[o].childNodes.length / 2);
var oarr = new Array(olen);
oarr[r] = order[o].attributes[0].value;
var leads = order[o].getElementsByTagName("lead");
// === BEGIN FOR 1 ===
for (var l = 0; l < leads.length; l++) {
// === BEGIN FOR 2 ===
for (var a = 0; a < leads[l].childNodes.length; a++) {
var lead = leads[l];
var t = 0;
var tarr = new Array();
// FOUND THE PROBLEM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for (s = 0; s < lead.childnodes.length; s++) {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
var prop = props[s];
if (prop.childNodes.length > 0) {
tarr[t] = prop.firstChild.data;
t++;
} else if (prop.tagName == "service") {
var varr = new Array();
for (var v = 0; v < prop.attributes.length; v++) {
varr[v] = prop.attributes[v].value;
}
} else if (prop.tagName == "supplier") {
var parr = new Array();
for (var p = 0; p < prop.attributes.length; p++) {
parr[p] = prop.attributes[p].value;
}
} else if (prop.tagName == "region") {
var garr = new Array();
for (var g = 0; g < prop.attributes.length; g++) {
garr[g] = prop.attributes[g].value;
}
}
tarr[t] = varr.join(";");
t++;
tarr[t] = parr.join(";");
t++;
tarr[t] = garr.join(";");
t++;
larr[e] = tarr.join("|");
e++;
// === END FOR 2 ===
}
// === END FOR 1 ===
}
oarr[r] = larr.join(".");
r++;
alert(oarr);
//addorder("list_leads", oarr);
// === END FOR 0 ===
}
if (xmldoc.getElementsByTagName("sql")[0]) if (xmldoc.getElementsByTagName("sql")[0].firstChild) var sql = xmldoc.getElementsByTagName("sql")[0].firstChild.data; if (sql != "") alert(sql);
// === ELSE END IF 1 ===
} else {
alert('There was a problem with the request.');
}
document.getElementById("ajaxbg").style.visibility = "hidden";
// === END IF 0 ===
}
}
this line is underlined in the code, but i don't see how that or anything near it could be the problem 0oError: syntax error
Source File: http://localhost/fab/scripts/ajax_leads.js
Line: 101, Column: 4
Source Code:
} else {
Last edited: