rihamd
rihamd

Reputation: 21

Fast consecutive XmlHttpRequest doesnt work

I have a code where when a div is clicked, an XmlHttpRequest is sent to a PHP script and some data is sent back. When the response is received by the client, some CSS work is done. But, if I click on a div and then after one second I click on another one, the second one doesn't fire the event.

How can I fix this issue?

Is there is a way to free memory after xmlhttp request is done?

This is my mousedown event function:

.on("mousedown",function () {


                var idgroup = $("#group_" + idBlock).val();
                var idProf = $(this).attr("name");
                if (window.XMLHttpRequest) {

                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                } else { // code for IE6, IE5

                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function () {

                    if (this.readyState == 4 && this.status == 200) {
                 // css color change is done here
                    }
                }
                xmlhttp.open("GET", "../dnd_jq/getProfTime.php?idprof=" + idProf + "&idgroup=" + idgroup);
                xmlhttp.send();


            }

Upvotes: 2

Views: 123

Answers (1)

Chromic Quanta
Chromic Quanta

Reputation: 11

Chances are the XHR object can't only fire if it is still waiting for a request. What I would do is make 2 XHR objects that fire for each request? P.S. I am very new to XHR and bad explanation skills, so take my response with a grain of salt!

Upvotes: 1

Related Questions