SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Ajax help?

  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax help?

    I'm trying to use Dustin Diaz ajax script here, but can't quite get it?

    http://www.dustindiaz.com/faster-ajax/

    Code JavaScript:
    asyncRequest('GET', requestURL, function(o) {
       ajaxSuccess(o.responseText);
      })

    this must not be how you call the function because my ajaxSuccess never gets fired?

    Code JavaScript:
    //ajax success
    function ajaxSuccess(o){
      var responseTxt = o.responseText;
        alert(  responseTxt);
    }


    Code JavaScript:
    var asyncRequest = function() {
      function handleReadyState(o, callback) {
        if (o && o.readyState == 4 && o.status == 200) {
          if (callback) {
            callback(o);
          }
        }
      }
      var getXHR = function() {
        var http;
        try {
          http = new XMLHttpRequest;
            getXHR = function() {
              return new XMLHttpRequest;
            };
        }
        catch(e) {
          var msxml = [
            'MSXML2.XMLHTTP.3.0',
            'MSXML2.XMLHTTP',
            'Microsoft.XMLHTTP'
          ];
          for (var i=0, len = msxml.length; i < len; ++i) {
            try {
              http = new ActiveXObject(msxml[i]);
              getXHR = function() {
                return new ActiveXObject(msxml[i]);
              };
              break;
            }
            catch(e) {}
          }
        }
        return http;
      };
      return function(method, uri, callback, postData) {
        var http = getXHR();
        http.open(method, uri, true);
        handleReadyState(http, callback);
        http.send(postData || null);
        return http;
      };
    }();

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,717
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    You're calling ajaxSuccess(o.responseText) where you pass o.responseText

    The ajaxSuccess function has an argument called o, that will contain o.responseText.

    Then, it tries to assign the responseText of that to a variable, so in effect you're trying to obtain o.responseText.responseText

    You may want to call ajaxSuccess(o) instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey pmw57, I've tried that:

    Code JavaScript:
        asyncRequest('GET', requestURL, function(o) {
                   ajaxSuccess(o);
              })

    doesn't seem to call ajaxSuccess?

    I also tried this:

    Code JavaScript:
    asyncRequest('GET', requestURL, ajaxSuccess)

    can't seem to get it to call ajaxSuccess?

  4. #4
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still not sure? what am I missing?

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There doesn't seem to be anything that sets http.onreadystatechange in that object you're using. Are you sure that script works at all?

    It looks like the line:
    handleReadyState(http, callback);

    should be
    http.onreadystatechange = handleReadyState(http, callback);

    but *shrug*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •