Wesley Skeen
Wesley Skeen

Reputation: 8295

how to manipulate a Jquery.ajax datatype

I have the following:

jQuery.ajax({
    type: "GET",
    url: "website/Function",
    data: '&link=' + link,
    contentType: "application/text; charset=utf-8",
    dataType: "text",
    success: function (data) {
        var Link = data.toString();
        $('link').val(Link);
    }
});

The value from link will be something like:

xml version="1.0" encoding="utf-8"?><string xmlns="http://tempuri.org/">blah /string

How can I manipulate this return value just to extract 'blah'?

'blah' can be dynamic

Thanks to anyone who helps.

Upvotes: 1

Views: 1051

Answers (2)

g19fanatic
g19fanatic

Reputation: 10961

To build off of ulvund's answer: use jQuery.parseXML():

jsfiddle

var xmlData = "<?xml version=\"1.0\" encoding=\"utf-8\"?><string xmlns=\"http://tempuri.org/\"> blah </string> ";

$("button").click(function() {
    xmlDoc = $.parseXML(xmlData);
    $xml = $(xmlDoc);
    $('#result').text($xml.find("string").text());
});

This is basically taken right off of jQuery's demo for parseXML()

Upvotes: 2

abcde123483
abcde123483

Reputation: 3905

Try

var result = $('link').find("string").text();

Upvotes: 0

Related Questions