Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2011, 08:52 PM   PM User | #1
jbrown1028
New Coder

 
Join Date: Sep 2006
Location: Fostoria, Ohio
Posts: 35
Thanks: 4
Thanked 0 Times in 0 Posts
jbrown1028 is an unknown quantity at this point
Ajax call is aborting previous call

I am having a small issues that I cannot figure out. I am basically trying to call the same page using a query string through the URL. Basically what I am trying to do is start on step 1, once that is done, move on to step 2, step 3, so on. What is happening is the step 1 - 6 will give this

GET http://securelivetest.com/custom/tes...p?action=step1 Aborted
GET http://securelivetest.com/custom/tes...p?action=step2 Aborted
GET http://securelivetest.com/custom/tes...p?action=step3 Aborted
GET http://securelivetest.com/custom/tes...p?action=step4 Aborted
GET http://securelivetest.com/custom/tes...p?action=step5 Aborted
GET http://securelivetest.com/custom/tes...p?action=step6 Aborted
GET http://securelivetest.com/custom/tes...p?action=step7 200 OK

The code is attached, any assistance would be greatly appreciated.

Thank you,
Jeff Brown

Code:
<?php
    $loadsystem = isset($_GET['action']) ? $_GET['action'] : "step1";
    if ($loadsystem == "step4"){echo "step 4";}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title> New Document </title>
        <script language="javascript" type="text/javascript">
            var ajaxObj = createXMLHttp();
            var Params = new Array('step1', 'step2', 'step3', 'step4', 'step5', 'step6', 'step7');
            for(var steps=0, len=Params.length; value=Params[steps], steps<len; steps++) {
                var url = 'ajax.php?action='+value;
                ajaxObj.open("GET", url, true);
                ajaxObj.onreadystatechange = handleAjaxResponse;
                ajaxObj.send(null);
            }

            function createXMLHttp() {
                if (typeof XMLHttpRequest != 'undefined')
                    return new XMLHttpRequest();
                else if (window.ActiveXObject) {
                    var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp","MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.5.0"];
                    for (var i = avers.length -1; i >= 0; i--) {
                        try {
                            httpObj = new ActiveXObject(avers[i]);
                            return httpObj;
                        } catch(e) {}
                    }
                }
                throw new Error('XMLHttp (AJAX) not supported');
            }

            function handleAjaxResponse(){
                if(ajaxObj.readyState == 4 && ajaxObj.status == 200) {
                    alert("handleAjaxResponse() called with ready state of " + ajaxObj.readyState);
                    var getVal = ajaxObj.responseText;
                    document.getElementById("mydiv").innerHTML=getVal;
                } else {
                    return false;
                }
            }

        </script>
    </head>
    <body>

    <div id="mydiv">
<?php
    if ($loadsystem) {
        echo "action: ".$loadsystem;
    }
?>
    </div>
    </body>
</html>
jbrown1028 is offline   Reply With Quote
Old 11-28-2011, 10:09 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
Yes, this is because you are starting requests with the same XMLHttpRequest object 7 times in a row ... without waiting for any of the single requests to finish before you create the next one.

The problem is the for loop. If you want to wait for step1 before you go to step2 etc you may only start a new request from inside the callback "handleAjaxResponse" with readyState==4 because this is "the place in your code" where the previous request has finished.

Last edited by devnull69; 11-28-2011 at 10:15 PM..
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:45 PM.


Advertisement
Log in to turn off these ads.