Note that there are some explanatory texts on larger screens.

plurals
  1. POjsp with ajax two simultaneous requests only getting one response
    primarykey
    data
    text
    <p>I have a jsp page where I'm trying to send multiple (two currently) ajax requests at once, but I only seem to get the second response. <a href="http://www.coderanch.com/t/121613/HTML-JavaScript/simultaneous-ajax-requests" rel="nofollow">This</a> guy described my problem exactly, but his solution didn't work for me.</p> <p>Here is my js code:</p> <pre><code> function createRequestObject(){ var req; if(window.XMLHttpRequest){ //For Firefox, Safari, Opera req = new XMLHttpRequest(); } else if(window.ActiveXObject){ req = new ActiveXObject("Microsoft.XMLHTTP"); } else{ //Error for an old browser alert('Browser error'); } return req; } function sendRequest(method, url, d){ var http = createRequestObject(); var div = d; if(method == 'get' || method == 'GET'){ http.open(method, url, true); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200){ var response = http.responseText; if(response){ document.getElementById(div).innerHTML = response; } } }; http.send(null); } } </code></pre> <p>And here is how I call that code:</p> <pre><code>QC1 Status: &lt;div id='qc1'&gt;blah&lt;/div&gt; &lt;br /&gt;UAT2 Status: &lt;div id='uat2'&gt;blah2&lt;/div&gt; &lt;a onclick="sendRequest('GET','index.jsp?qc1.properties=true','qc1'); " href="#"&gt;qc1&lt;/a&gt; &lt;a onclick="sendRequest('GET','index.jsp?uat2.properties=true','uat2'); " href="#"&gt;uat2&lt;/a&gt; &lt;a onclick="sendRequest('GET','index.jsp?qc1.properties=true','qc1'); sendRequest('GET','index.jsp?uat2.properties=true','uat2'); " href="#"&gt;both&lt;/a&gt; </code></pre> <p>When I call one at a time they work as expected, but the "both" link only updates with the second request, even though I know it runs the index.jsp code for both.</p> <p>EDIT: Ok, after fixing the obvious mistake that BalusC pointed out, it works. Fixed it in this post too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload