1

I'm making an AJAX call to a page that returns XML. It turns out that I need to also return another standalone value, along with the XML.

Here is the JQuery AJAX call:

$.ajax({
        type: "GET",
        url: "filesearch.asp",
        data: "action=getresponse,
        dataType: "text",
        cache: false, 
        success: function(data){

        var parsed   = data.split('DELIMITER');
        var xml      = data[0];
        var myvalue  = data[1];
}

The page that sends the response sends the XML and my value separated by the DELIMITER string. Also, I set the dataType so that it treats the full response as a text, and I'm assuming I should be able to simply split the string at the delimiter and access both values in my success function. Firebug shows I get the full response correctly, but when I log xml and myvalue to the console, I get:

xml = < 
myvalue = ?

Any ideas what I'm doing wrong or how to troubleshoot?

3 Answers 3

2

As you already noticed: you have to use parsed instead of data...

But: Do not use plain-'text' but 'json' as your data type and change your asp script to output valid JSON. Then data is a JavaScript object so you don't have to mess around with splitting strings etc.

Sign up to request clarification or add additional context in comments.

1 Comment

@ Thief - Good idea. I actually turn the XML to JSON in my callback, but if I can send it in that format to begin with that would be great. Any pointers on the best way to accomplish this in ASP?
1

Wow. Should've been:

var **parsed**   = data.split('DELIMITER');
var xml      = **parsed**[0];
var myvalue  = **parsed**[1];

Comments

1

Just to add to your answer.

the reason you are seeing < and ? is because data is text which is an array of characters and as the xml starts as <?xml the first and second (0th and 1st) values are < and ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.