Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts

    Can I fire off 2 ajax instances?

    I am launching the first ajax instance and doing some file processing on my server. While waiting for this I have a stop link that I want to click on to stop this first ajax process (if I get tired of waiting for example).

    The stop link fires off a separate ajax instance that, on the server side, simply sets a global php flag to abort. The first ajax procedure constantly checks this flag.

    Can I create two ajax http instances? In my code below, I create http and httpStop.

    It doesn't seem to be working so I'm wondering if what I'm doing is possible?

    PHP Code:
    function createRequestObject() {
        if (
    window.XMLHttpRequest) { // Mozilla, Safari, Opera...
            
    var xmlhttp = new XMLHttpRequest();
            if (
    xmlhttp.overrideMimeType)
                
    xmlhttp.overrideMimeType('text/xml');
        }
        else if (
    window.ActiveXObject) { // IE
            
    try {
                var 
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (
    e) {
                try {
                    var 
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (
    e) {}
            }
        }
        if (!
    xmlhttp) {
            
    alert('Giving up :( Cannot create an XMLHTTP instance');
            return 
    false;
        }
        return 
    xmlhttp;
    }
    var 
    http createRequestObject();
    var 
    httpStop createRequestObject(); 
    The ajax code is pretty straight forward for both of these ajax functions so I'm not listing them here - my question is more of a structural ajax question: can I fire off two ajax functions if they each have their own createRequestObject?

    Thanks
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    the second instance will be created after http.abort() in the click event or what ever you use in that link so I don't see a problem here.

    best regards

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    I'm not using http.abort() - when I click on the 2nd ajax link it just calls a php script on the server and it sets a global php var. The 1st Ajax instance is still processing files and will ck this bar in it's loop. So I can't use http.abort(). I need 2 Ajax instances running for a brief time period at least, at the same time. Can this be done? That's why I used httpStop to create the 2nd instance.
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by rfresh View Post
    I'm not using http.abort() - when I click on the 2nd ajax link it just calls a php script on the server and it sets a global php var. The 1st Ajax instance is still processing files and will ck this bar in it's loop. So I can't use http.abort(). I need 2 Ajax instances running for a brief time period at least, at the same time. Can this be done? That's why I used httpStop to create the 2nd instance.
    try this:

    https://blueprints.dev.java.net/ajax...rrent_requests

    best regards

  • Users who have thanked oesxyl for this post:

    rfresh (05-02-2009)


  •  

    Posting Permissions

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