/    Sign up×
Community /Pin to ProfileBookmark

Good afernoon.

Currently we see that XMLRequests are starting to be used as an alternative (like [URL=http://www.google.com/webhp?complete=1&hl=en]Google Suggest[/URL]) to reloading all the page every time a request is made to server.

But as I try to use it, I end up with some doubts and problems, like:

  • What happens when a first request is made to the server and when some elements in the page (like a div, textarea, etc.) are being chnaged, the user clicks other parts of the page and makes a second request to the server? Can the page become inconsistent?

  • Is it possible to do a request inside another one? That is, when the first request is received is it possible to do a second request? I’ve tried it, but Mozilla Firefox ends up in an infinitive loop.

  • Thanks for your help,
    Migrate

    to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @Khalid_AliJan 30.2005 — mozilla does only logical thing, when you have a request in request unless there are checks to stop it, don't you think it will be run in an infinite loop?
    Copy linkTweet thisAlerts:
    @MigrateauthorJan 30.2005 — Hello Khalid Ali!

    Thanks for your anwser.

    In fact I have a way to abort the request, but it doesn't seem to work in Mozilla Firefox. It works in IE6.

    All I do is a first request to the server and when I get the result from that request, I try do to a second one.

    To better ilustrate the problem, I will show the actual code:

    [code=php]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


    <html>
    <head>
    <title>XML Request Test 2</title>
    <script type="text/javascript" src="scriptsgeneric.js"></script>
    </head>
    <body>


    <input id="str" name="str" type="text"/>
    <button onclick="start()"> GET </button>
    <br />
    <br />

    <textarea id="area" cols="40" rows="10"></textarea>

    <script>

    function getRequest(){
    var req=null;
    try{
    req=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(ex){
    try{
    req=new ActiveXObject("Microsoft.XMLHTTP");
    }catch(o){
    req=null;
    }
    }

    if(!req&&typeof XMLHttpRequest!="undefined") {
    req=new XMLHttpRequest();
    }
    return req;
    }

    var serverOpen;

    function openGet(linkHREF, onloadFunction){
    if(serverOpen&&serverOpen.readyState!=0){
    serverOpen.abort();
    }
    serverOpen=getRequest();
    if(serverOpen){
    serverOpen.open("GET",linkHREF,true);
    serverOpen.onreadystatechange=function() {
    if(serverOpen.readyState==4){

    area.value = area.value + "+++++++++ REQUEST +++++++ n";
    // first request.
    onloadFunction(serverOpen.responseText);

    }
    }
    ;
    serverOpen.send(null)
    }
    }

    var area = document.getElementById("area");
    var str = document.getElementById("str");

    function start() {

    // first get.
    var linkHREF = "request/rec2?str="+str.value;
    openGet(linkHREF, receivedFirstGet);

    }


    function receivedFirstGet(text) {

    // received first request.
    area.value = area.value + "******* First get ****** n" + text + "n";

    // getting second get.
    var linkHREF = "request/rec2?str="+str.value;
    openGet(linkHREF, receivedSecondGet);

    }

    function receivedSecondGet(text) {

    area.value = area.value + "******* Second get ****** n" + text + "n";

    }

    </script>

    </body>
    </html>

    [/code]


    Thanks again,

    Migrate
    ×

    Success!

    Help @Migrate spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.3,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...