Results 1 to 3 of 3

Thread: Ajax & Javacript Array Problem XMLHTTPRequest Multi-Instance Problem ....

  1. #1
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Ajax & Javacript Array Problem XMLHTTPRequest Multi-Instance Problem ....

    1st of all sorry i Posted this In Another Forum By Mistake and I Can't Delete If From There ....

    What I'm Asking About Can I Send 2 Requests At The Same Time .. And They Work In Parallel ?? Example If There's 2 Polls In 1 Page .. And Someone Clicked On The 1st One And Click On The 2nd Before The 1st One Is Finished ... is It Possible To Make Array Of Requests ??? The Below Code Doesn't Work .....If I Just Got The Response I Can Handle It Later But Please Tell Me How To Create multi Instance Of The XMLHTTPRequest ...

    Code:
    var req=new Array();
    var The_ID=new Array();
    // The_ID is An Array Containing The IDs Of Any HTML Part That The Result Of Any Request Will be Executed At E.g Any TD Or something in any table in the HTML ... 
    function sR(url,params,HttpMethod,anyID){
    	if (!HttpMethod)
    	{
    		HttpMethod="POST";
    	}
    	The_ID[req.length]=anyID;
    	req[req.length]=initXMLHTTPRequest();  // The Problem Is Here .. 
    	for (i=0;i<req.length;i++)
    	{
    		if (req[i]){
    			req[i].onreadystatechange=onReadyState(i);
    			req[i].open(HttpMethod,url,true);
    			req[i].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    			req[i].send(params);
    		}
    	}
    function initXMLHTTPRequest(){
    	var xRequest=null;
    	if (window.XMLHttpRequest)
    	{
    		xRequest=new XMLHttpRequest();
    	} 
    	else if (window.ActiveXObject)
    	{
    		xRequest=new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	else {
    	}
    return xRequest;
    }

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Because the XMLHttpRequest object is asynchronous (the A in AJAX), you don't need to use more than one. Just check which page the data is coming from in onreadystatechange().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Hmm .. And How Do I Do That ?? I Already Did It Using An Array I Fixed The Above Code the Problem was that I Have To Use req.push instead of req[req.length] cause .push is more suitable to add objects .....

    but can u please tell me the other way in more details or mail it to me
    Code:
    m_m_shehab@hotmail.com

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
  •