I'm using ajax to开发者_开发问答 return some data from my server. What I get is a data string object.
How can I parse this html object, so that I only get a part of this returned data?
Depends on the dataType
. What kind of data do you expect to receive and which dataType
do you specify in the jQuery .ajax()
method?
If you specfiy json
for instance, jQuery (since version 1.3.2 I guess) will try to parse the received data into a Javascript object. But in general, you can just modify the received data yourself with all String methods
available.
$.ajax({
url: '...',
dataType: 'text',
success: function(data) {
//var part = data.substring(0,8);
$(data).find('#my_element');
}
});
This would take only the first 8 characters from the received data. Another way is to apply a regular expression
on your received data. All on you.
edit
Based on your comment: If your transfer a valid HTML chunk of data, you can just wrap that data into a jQuery contructor and use all methods available there, for instance .find()
精彩评论