x1nick Posted August 16, 2009 Share Posted August 16, 2009 Im still learning javascript at the moment, so bare with me on this. I need to make 2 ajax requests when a user presses a button, which update two separate divs. My ajax file (any constructive opinions on my class would be appreciated too! don't know how good it actually is) function ajaxclass () { var xmlhttp; this.request = request; function GetXmlHttpObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveXObject("Msxml2.XMLHTTP")) { return new ActiveXObject("Msxml2.XMLHTTP"); } if (window.ActiveXObject("Microsoft.XMLHTTP")) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } function request(url,loaded,loading) { xmlhttp = GetXmlHttpObject(); if (xmlhttp == null) { alert ("Browser does not support HTTP Request"); return; } xmlhttp.onreadystatechange = function() { switch(xmlhttp.readyState) { case 0: // Uninitialized break; case 1: // Loading if (loading != "") { eval(loading); } break; case 2: // Loaded break; case 3: // Interactive break; case 4: // Done! response = xmlhttp.responseText; eval(loaded); break; default: break; } } xmlhttp.open("GET",url,true); xmlhttp.send(null); } } var ajax = new ajaxclass(); It does work, but I have a problem when carrying out 2 requests. The button runs this function <script type="text/javascript"> function doupdate (tplid) { var result = confirm('Are you sure you want to update {tplname}?'); if (result) { openmessage(); ajax.request('index.php?s=ajax&acms&amod=tpl&ajax=update&tplid='+tplid, 'document.getElementById(\'messagearea\').innerHTML = response;',''); ajax.request('index.php?s=ajax&acms&amod=tpl&ajax=results', 'document.getElementById(\'filterreslts\').innerHTML = response;',''); } } </script> Now firebug says both run, and both scripts return a response. The 2nd ajax request dispalys a result, but the first dosen't. If the 2nd request is removed the first one works, and displays the message in the correct area. Why is it when both are run, that the message is not displayed but firebug reports it as returning the required result? PS openmessage() simply sets a div to display.style = 'block' which works, but the div is empty. Quote Link to comment Share on other sites More sharing options...
x1nick Posted August 16, 2009 Author Share Posted August 16, 2009 Should really look at my code more before posing. Noticed I was making xmlhttp global within the class which caused the problm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.