SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to get multiple result using ajax

    Hi Friends!
    I am experimenting with Ajax. I am able to execute the code. But only the concern iam having now is "i dont know how to get results in array format from server...". Using the xmlHttp.responseText object i can get only one value. Is there any way to get an array from server. Cud anybody can help me regarding this.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could parse the responseText and make an array out of it, for example, if your server is returning:

    1,2,3,4,5

    do

    var myArray = xmlHttp.responseText.split(",");

    Or you could output the server stuff as XML and use xmlHttp.responseXML (I think that's x-browser) and parse the XML into an array.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any way to get an array from server.
    No. You get a string(responseText) or you get an xml document(responseXML). If the file you request looks like this:

    somefile.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <anything>
    	<data>hello world</data>
    	<data>goodbye</data>
    </anything>
    you can do this:
    Code:
    var dataTags = req.responseXML.getElementsByTagName("data");
    var myArray = [];
    for(var i = 0, len = dataTags.length; i < len; i++)
    {
    	alert(dataTags[i].firstChild.nodeValue);
    	
    	myArray[i] = dataTags[i].firstChild.nodeValue;
    }
    
    alert(myArray);


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
  •