Results 1 to 3 of 3

Thread: AJAX stops at onreadystatechange function

  1. #1
    Join Date
    Dec 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default AJAX stops at onreadystatechange function

    Okay so I have this ajax code below, and it doesn't work... It doesn't even get into the onreadystatechange function, can anyone tell me what i've done wrong. Thank-you so much I've been working on this for 2 days!


    PHP Code:
    var response false;

    function 
    AJAXGet (urltarget) {

        
    httpRequest = new XMLHttpRequest();

        
    httpRequest.open ('GET'urltrue);

        
    httpRequest.onReadyStateChange = function () {

            if (
    httpRequest.stateChange==4) {

                if (
    httpRequest.status==200) {

                    if (
    target=='self') {

                        
    response httpRequest.responseText;

                    }

                }

            }

        };

        return 
    response;

        
    httpRequest.send(null);



  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try changing it to this:
    Code:
    var response = false;
    
    function AJAXGet(url, target) {
    
        httpRequest = new XMLHttpRequest();
    
        httpRequest.open('GET', url, true);
    
        httpRequest.onReadyStateChange = function () {
    
            if (httpRequest.stateChange==4) {
    
                if (httpRequest.status==200) {
    
                    if (target=='self') {
    
                        response = httpRequest.responseText;
    
                    }
    
                }
    
            }
    
        }
    
        return response;
    
        httpRequest.send(null);
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Feb 2006
    Posts
    225
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default

    There have been no replies, so I don't know if it is solved. But if it is still a problem, it may be that your
    Code:
    httpRequest.onReadyStateChange = function ()
    should be
    Code:
    httpRequest.onreadystatechange = function ()
    and that it should appear after the open. See http://www.dynamicdrive.com/forums/s...ad.php?t=27081 for a script that works - just tailor it a little to get back your response text.

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
  •