B
bizt
Hi,
I have a web app that makes requests to the server using
XmlHttpRequest object. I have created a js ajax wrapper function/class
(AjaxWrapper) that I can instantiate as an object and each object is
designed to make its own unique request (if I need to make two,
requests I would create two obejcts). Normally the object is created
within a function and will die at the end of that function call:
function doRequest() {
var oAjax = new AjaxWrapper;
oAjax.url = "data/getInfo.php";
oAjax.onSuccess = function() {
// handler code goes here
}
oAjax.get(); // this command makes the request
}
Problem:
I'm trying to identify a bug in which I suspect two requests that
share global variables (outside the caller function - doRequest in the
above example) are very occasionally being executed at the same time.
Now, I have to accept that this can happen as I have a feature that
automatically makes the requests without the users command but also
the user can make the same request at any time by other means. Anyway
I think that perhaps whilst one request is being made and another in
parallel at the same time when they are both being handled because
they share some variables one requests handling may be screwing up the
others.
Solution(?):
I decided that it should be a good idea to have some kinda of flag
that tells the system that this process is currently being handled, go
away. That way I wont have two requests being handled at the same
time. In fact, better yet may even be to have a flag to say that a
request is under way to prevent another call to the server even being
made. Good idea?
Now what I really could also do with, when I make a request it would
be neat if I could log the request ID if exists and when I get the
response I can check its request ID to see if it was the last request
made. Does XHR have this included or do I need to pass this when I
make my request and return it as part of my response generated. See
example:
Request
oAjax.url = "data/getInfo.php?id=153452345353"; // this is the request
with id in GET
Response
<response>
<data id="153452345353">..</data>
</response>
Would be much easier for me however if something already exists within
XHR and I dont need to make any changes to schema of the generated DSV
string (Ive just used XML in the above example for simplicity)
Anyway this may not even be the cause of the bug as its one of those
very inconsistent bugs that when you perform the same steps it works
the next 100 times however doesn't give the client much confidence. I
think it would be a good idea to ensure that only a single request is
being made/handled anyway so these steps are perhaps a good idea. If
anyone has any techniques or have encountered similar problems please
let me know, would be very much appreciated as this is the first time
Ive really had to consider this issue.
Thanks
Burnsy
I have a web app that makes requests to the server using
XmlHttpRequest object. I have created a js ajax wrapper function/class
(AjaxWrapper) that I can instantiate as an object and each object is
designed to make its own unique request (if I need to make two,
requests I would create two obejcts). Normally the object is created
within a function and will die at the end of that function call:
function doRequest() {
var oAjax = new AjaxWrapper;
oAjax.url = "data/getInfo.php";
oAjax.onSuccess = function() {
// handler code goes here
}
oAjax.get(); // this command makes the request
}
Problem:
I'm trying to identify a bug in which I suspect two requests that
share global variables (outside the caller function - doRequest in the
above example) are very occasionally being executed at the same time.
Now, I have to accept that this can happen as I have a feature that
automatically makes the requests without the users command but also
the user can make the same request at any time by other means. Anyway
I think that perhaps whilst one request is being made and another in
parallel at the same time when they are both being handled because
they share some variables one requests handling may be screwing up the
others.
Solution(?):
I decided that it should be a good idea to have some kinda of flag
that tells the system that this process is currently being handled, go
away. That way I wont have two requests being handled at the same
time. In fact, better yet may even be to have a flag to say that a
request is under way to prevent another call to the server even being
made. Good idea?
Now what I really could also do with, when I make a request it would
be neat if I could log the request ID if exists and when I get the
response I can check its request ID to see if it was the last request
made. Does XHR have this included or do I need to pass this when I
make my request and return it as part of my response generated. See
example:
Request
oAjax.url = "data/getInfo.php?id=153452345353"; // this is the request
with id in GET
Response
<response>
<data id="153452345353">..</data>
</response>
Would be much easier for me however if something already exists within
XHR and I dont need to make any changes to schema of the generated DSV
string (Ive just used XML in the above example for simplicity)
Anyway this may not even be the cause of the bug as its one of those
very inconsistent bugs that when you perform the same steps it works
the next 100 times however doesn't give the client much confidence. I
think it would be a good idea to ensure that only a single request is
being made/handled anyway so these steps are perhaps a good idea. If
anyone has any techniques or have encountered similar problems please
let me know, would be very much appreciated as this is the first time
Ive really had to consider this issue.
Thanks
Burnsy