how would i write this request in jquery?

Discussion in 'Javascript' started by Shawn Bright, Feb 13, 2012.

  1. Shawn Bright

    Shawn Bright Guest

    Hey all, i have a request i am making with prototype that i need to do in jquery.

    var url = "/sites/new_info";
    new Ajax.Request(url, {
    method: 'get',
    onSuccess: function(response) {
    var sites = response.responseJSON;

    appreciate any help.
    Shawn Bright, Feb 13, 2012
    1. Advertisements

  2. Have you read the docs?
    That code does what you have coded. Whats wrong with it?

    Andreas Bergmaier, Feb 13, 2012
    1. Advertisements

  3. Shawn Bright

    Shawn Bright Guest

    oh, it works fine, but i need to do the same thing in jQuery.
    Shawn Bright, Feb 14, 2012
  4. On Mon, 13 Feb 2012 19:43:33 -0800 (PST), Shawn Bright

    Why? What does it gain you?


    Gene Wirchenko
    Gene Wirchenko, Feb 14, 2012
  5. jQuery is not very popular here, to put it mildly.

    It may be a good idea to visit jQuery's own forum and ask there.
    I'm pretty sure you will get the answer there.

    Hans-Georg Michna, Feb 14, 2012
  6. Seeing as you're just jumping from one lost cause to another,
    I'll throw you a rope. What you're interested in using is
    actually the XMLHttpRequest API[0] which is often aliased
    as "AJAX" by marketers and fools.

    Secondly, you'd be well-advised to steer clear of Prototype.js.
    Richard Cornford has a well-known quote here regarding it. I
    believe Thomas Lahn still has it randomly pop up in his "signature"
    from time to time. I'll give you a hint: it's pretty scathing.

    I'd suggest digging through the XMLHttpRequest API
    documentation to understand how it truly works. That said,
    David Mark has a module in his My Library API[1] that
    covers "AJAX"[2]. I'd recommend at least giving it a
    test drive. It will mask warts in IE relating to ActiveX
    and other follies. For a clear beginner, that's a good idea.

    Matt McDonald, Feb 14, 2012
  7. As my sig is chosen randomly, and I do not want to look that one up right
    now, it is not the one you are looking for here. But the one here is put
    equally aptly.
    Looking into the newer XMLHttpRequest2 API would be useful as well, as there
    are implementations of it in browsers. I have not had the time to consider
    it for JSX as yet, but it looks promising.
    The last time we discussed this here, David's code was slightly flawed in
    that it always used XMLHttpRequest() even if the request URI used the
    `file:' scheme (where XMLHttpRequest() is known not to work in MSHTML). My
    code tries to use ActiveXObject() first which has no such limitations.
    JFTR: Using JSX:http.js [1], which is (also?) built on (more) sound
    principles of software design, and rather well field-tested, that would be

    var Request =;

    var req = new Request("/sites/new_info", "GET", true,
    function (response) {
    var sites = response.responseJSON;



    var req = new Request("/sites/new_info");

    req.setSuccessListener(function (response) {
    var sites = response.responseJSON;


    … assuming that `responseJSON' was a built-in host property.

    Aliasing `Request' is optional then, of course, but it can improve
    efficiency if done in the right place. jsx._import() would be another

    [1] <>
    Thomas 'PointedEars' Lahn, Feb 18, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.