ndesign11
ndesign11

Reputation: 1779

jquery ajax is loading entire external html rather than targeted div

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

Answers (1)

charlietfl
charlietfl

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

Related Questions