Get page by jQuery
开发者_运维问答Here is my js:
$.ajax({
url: "test.html",
error: function(){
//do something
}
success: function(){
//do something
}
});
It gets test.html, how do I operate with received data inside success function?
Like every Ajax success handler, the callback gets passed in the received data. The type of the data can vary, depending on the dataType.
In your case it's a plain text response (hopefully well HTML formatted). If so, you could just wrap the response into a jQuery constructor function and act on that.
$.ajax({
url: "test.html",
error: function(){
//do something
}
success: function(data){
// data contains the received HTML file
$(data).find('.someclass').css('color', 'BADA55').appendTo('.somewhere');
}
});
It actually only makes sense, that .somewhere
represents an <iframe>
element. This is because you cannot have multiple <HTML>
, <BODY>
or <HEAD>
nodes in your markup. So appending a complete HTML file into a <DIV>
would cause an invalid HTML markup and that is asking for trouble.
精彩评论