Reputation: 1779
I have a simple ajax request loading in an external html file but it's pulling in the entire page rather than just the specific div I requested. Does this only work using the .load?
$.ajax({
url: 't3.html #test',
success: function(data) {
$('.incoming').append(data);
}
});
Upvotes: 0
Views: 528
Reputation: 171669
Use load()
method which will filter the external page for the selector you want
$('.incoming').load('t3.html #test');
Otherwise using other AJAX methods you would need to create your own filter, they do not parse the url for the content themselves:
$.ajax({
url: 't3.html',
success: function(data) {
var div=$(data).find(' #test'); /* if #test not wrapped in parent use filter instead of find*/
$('.incoming').append(div);
}
});
Refernce: http://api.jquery.com/load/
Upvotes: 2