0

How can i create a new Ajax object everytime for a particular ajax request, using Prototype library? It seems in Prototype, "Ajax" is a global object and all reqs are its instances. Please help..

Thanks

4
  • 4
    I'd answer this, but I'd have to Google the Prototype docs, grok them, and then give you the answer you could have given yourself if you had done this instead. Commented Apr 23, 2009 at 5:19
  • 1
    So what's your use case for this? Do you want to store the requests somewhere to keep track of them or what? As stated by apphacker, the docs are readily available ( prototypejs.org/api/ajax/request ) and should provide sufficient info on how the Ajax-class works in Prototype. But before anyone can give you a proper answer, could you please specify why you'd want to have separate objects for each request. Commented Apr 23, 2009 at 5:40
  • 2 concurrent Ajax requests sent to the server do not get back with their respective responses. Instead only one response returns correctly and the other response is empty. Earlier when i had posted in other forums and in this forum, people advised using new Ajax objects not only new ajax request instances. So the question Commented Apr 23, 2009 at 10:34
  • And the Ajax requests were sent at the same instant from multiple tabs in the same browser window of the same appl page on the same submit button Commented Apr 23, 2009 at 10:36

1 Answer 1

1

Actually, Prototype creates a new "instance" for each request. You do it like this:

var request = new Ajax.Request('/your/url', {
  onSuccess: function(transport) {
      // yada yada yada
  }
});

Normally you skip the "var request = " part, unless you need access to the public properties of the instance. One possible reason would be to access the "transport" property which contains the "raw" XMLHttpRequest object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.