i have javascript function reads xml. function, calls second function prompt user update start price value. first time has error. 2 uncaught rangeerror: maximum call stack size exceeded. 43 uncaught invalidstateerror: failed execute 'send' on 'xmlhttprequest': object's state must opened.
i not sure going on here? recursion problem? if so, how can solve this?
this javascript:
var xmlhttp=false; if (window.xmlhttprequest) { xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } function loadxmldoc() { var table var i; xmlhttp.open("get","auction.xml",false); xmlhttp.send(); xmldoc=xmlhttp.responsexml; table=("<table border='1'><tr><th>item name</th><th>category</th><th>start price</th></tr>"); var x=xmldoc.getelementsbytagname("product"); (i=0;i<x.length;i++) { table+=("<tr><td>"); table+=(x[i].getelementsbytagname("itemname")[0].childnodes[0].nodevalue); iname=(x[i].getelementsbytagname("itemname")[0].childnodes[0].nodevalue); table+=("</td><td>"); table+=(x[i].getelementsbytagname("owner")[0].childnodes[0].nodevalue); iowner=(x[i].getelementsbytagname("owner")[0].childnodes[0].nodevalue); //document.getelementbyid('test').innerhtml=iowner; table+=("</td><td>"); table+=(x[i].getelementsbytagname("startprice")[0].childnodes[0].nodevalue); table+=("</td><td>"); table+="<input type=\"submit\" onclick=\"itembid('"+ iname + "','"+ iowner +"')\" value=\"bid\">"; table+=("</td></tr>"); } table+=("</table>"); document.getelementbyid('listinglist').innerhtml=table; } function itembid(iname,iowner) { var newbid = prompt("please enter bidding price"); var itemname = iname; var ownername = iowner; //document.getelementbyid('test').innerhtml=ownername; //document.getelementbyid('test').innerhtml="aa"; xmlhttp.open("get", "readxml.php?newbid=" + encodeuricomponent(newbid) + "&itemname=" + encodeuricomponent(itemname) + "&ownername=" + encodeuricomponent(ownername) +"&date="+ number(new date), true); xmlhttp.onreadystatechange = loadxmldoc; xmlhttp.send(); }
you need have new request reach request try
function getxmlhttp() { var xmlhttp = false; if (window.xmlhttprequest) { xmlhttp = new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp = new activexobject("microsoft.xmlhttp"); } return xmlhttp; } function loadxmldoc() { if (this.readystate != 4 || this.status != 200) { return; } var table var i; var xmlhttp = getxmlhttp(); xmlhttp.open("get", "auction.xml", false); xmlhttp.onreadystatechange = function () { if (xmlhttp.readystate != 4 || xmlhttp.status != 200) { return; } var xmldoc = xmlhttp.responsexml; table = ("<table border='1'><tr><th>item name</th><th>category</th><th>start price</th></tr>"); var x = xmldoc.getelementsbytagname("product"); (i = 0; < x.length; i++) { table += ("<tr><td>"); table += (x[i].getelementsbytagname("itemname")[0].childnodes[0].nodevalue); iname = (x[i].getelementsbytagname("itemname")[0].childnodes[0].nodevalue); table += ("</td><td>"); table += (x[i].getelementsbytagname("owner")[0].childnodes[0].nodevalue); iowner = (x[i].getelementsbytagname("owner")[0].childnodes[0].nodevalue); //document.getelementbyid('test').innerhtml=iowner; table += ("</td><td>"); table += (x[i].getelementsbytagname("startprice")[0].childnodes[0].nodevalue); table += ("</td><td>"); table += "<input type=\"submit\" onclick=\"itembid('" + iname + "','" + iowner + "')\" value=\"bid\">"; table += ("</td></tr>"); } table += ("</table>"); document.getelementbyid('listinglist').innerhtml = table; }; xmlhttp.send(); } function itembid(iname, iowner) { var newbid = prompt("please enter bidding price"); var itemname = iname; var ownername = iowner; //document.getelementbyid('test').innerhtml=ownername; //document.getelementbyid('test').innerhtml="aa"; var xmlhttp = getxmlhttp(); xmlhttp.open("get", "readxml.php?newbid=" + encodeuricomponent(newbid) + "&itemname=" + encodeuricomponent(itemname) + "&ownername=" + encodeuricomponent(ownername) + "&date=" + number(new date), true); xmlhttp.onreadystatechange = loadxmldoc; xmlhttp.send(); }
Comments
Post a Comment