How to execute ajax script on Jquery mobile?

How to get AJAX requests to respond to all requests?

  • I'm using jquery now, hoping it will let me make more than 2 ajax requests. Apparently it did not. Here's the lowdown: I'm working on XAMPP, and there's a single javascript function called; it uses AJAX to check if the queried data exists in the database. It happened it must do it twice. In the first one: var request = "?ajax=rblist&do=threadlookup&query="+do… Which returns stuff fine. THE PROBLEM IS IN THE SECOND... var rbget = jQuery.ajaxSync({ url: rbrequest, async: false }).responseText; It either returns blank or undefined. This had me stumped. If this is caused by ajax requesting too quickly, how should I make the script pause? If there's a syntax in jquery to do it, how? I've read around sites, and no one has been giving them answers about problems like this.

  • Answer:

    You might want to use a packet sniffer to find out what's going on...wireshark or fiddler will work fine. IE has a limit of 2 connections to a server (You can tweak it in the registry to bump it up) so that might be affecting it as well. You might also try to stack the calls something like what's below. I'm not familiar with the ajax queue plugin and I have no idea if what's below will work or not but you're assured that the second call will be made synchronously. Obviously with more than two calls something like the method below would get ugly. $.post("/myAjax", { parm1: $("#someField").attr("value"), parm2: $("#pass1").attr("value") },function(JSONData){ eval(JSONData); $.post("/myOtherAjax"), { parm1: "something here" }, function(returnData) { //do something }); }); Edit: When IE is communicating to the server it will only open 2 connections to the server. This is a known bottleneck in IE, and slows down the loading of the pages. (1st link below) Firefox and Chrome are set higher but I'm not exactly sure by how much. You can change IE and possibly speed up the page load time. (2nd link) By default those jQuery ajax calls are async so the second one is fired off without waiting for the first one to complete. You might want to try setting async to false for your first query. A packet sniffer will give you some great insight as to what goes on when your ajax calls fire off. Wireshark is fine for this, in spite of what some people say. Fiddler works fine too or find another one you like. P.S. If you're going to go through the trouble of bashing what other people say it's usually a good idea to offer up a better solution at the risk of looking like an idiot.

herman near at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Okay first off, wireshark? Really other guy??? Secondly. Yes! jQuery will allow to make 2 requests. It has no idea that you just made a previous request. You are going off on a mental tangent right now. You have not told us nearly enough info to actually help you. If you had shared what are you trying to accomplish then we could tell you the correct way to do it. Because obviously the way you are looking at this is wrong. To be honest I doubt you even need two requests. There is always json for groups of data. If you are trying to get a response then make another ajax call based on that response - why? Why would you not have all the logic contained in the first call?? Javascript does have settimeout - but i seriously doubt that is in anyway the appropriate tact to take. wireshark.. heheh. Also - "IE has a max of 2 connections to a server" What the hell does that even mean??? HTTP is stateless and AJAX is NOT a persistent connection. There is no connection. It's all call and response for pete's sake.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.