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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts

    responseText and responseXML

    In response to an Ajax call, there could be two kinds of retuns:

    DOMString responseText;
    Document responseXML;

    1)For the responseText, what is the differences as compared to the responseXML?

    2)For what purposes should return responseText not responseXML, or vice versa?

    3)For DOMString responseText, can I use the getElementById, documentElement functions?




    Thanks


    Scott

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    responseText returns a string, and it is just a string. If you need to parse data from it, it can only be done with string handling methods.

    responseText is good if you're okay with using innerHTML, which as of so far is not standards compliant. You can just set the innerHTML of an object to the returned responseText and it will appear in the document.

    responseXML returns an XML doc, that can be accessed and parsed using normal DOM methods.

    You have more control over the data using xml, while using the string it is easier to retrieve bits of html that can be displayed as a whole.

    Does that answer your question?

    I'm going to go ahead and move this to the ajax discussion section.
    Helping to build a bigger box. - Adam Matthews

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I use the text method. The first characters are a confirmation of which PHP is returning. This is stripped away. I then divide up the records with split() with a special character "^". The individual records are divided into their variables using another Split() then the values are put into a string of HTML code which is then moved the screen using the innerHTML method.

    var responseresult=xmlHttp.responseText;

    // RETURN OF LIST AND THEN SEND TO SCREEN

    if(responseresult.search(/php response: harvest_list_harvesters.php/)>-1)
    {

    var list_results = responseresult.replace(/php response: harvest_list_harvesters.php/,"")

    var list_SplitResult = list_results.split("^");

    var output_list = "";

    //note: the length is subtracted by 1 because the split adds an extra record to the array at the end

    var record_key = "";
    var record_firstname = "";
    var record_lastname = "";

    var record_SplitResult= new Array();

    for(i=0;i<list_SplitResult.length-1;i++)
    {

    record_SplitResult = list_SplitResult[i].split("|");

    record_key = record_SplitResult[0];
    record_firstname = record_SplitResult[1];
    record_lastname = record_SplitResult[2];

    output_list += "<input type=\"button\" onclick=\"ajaxFunction('harvester_key=" + record_key + "','harvest_get_harvester.php');\" value=\"" + record_lastname + ", " + record_firstname + "\"/><br/>";

    }

    document.getElementById('harvesterlist').innerHTML="<b>HARVESTERLIST:<br></b>" + output_list;
    }


  •  

    Posting Permissions

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