How to select contents of element with jquery .ajax
I have this jquery code:
$.ajax({
url:'ajax/windowshop.php',
context:'#windowShop',
success:function(data){
$('#windowShop').append(data);
}
})
I want to select the contents of #windowShop from the page ajax/windowshop.php and insert them into an element on the curren开发者_JAVA百科t page. I can't find much documentation on context when using the ajax command and this doesn't seem to work because data contains the whole page 'ajax/windowshop.php' and not just the contents of ('#windowShop') in ajax/windowshop.php.
You could select the content from the data
coming back. For example if all of the main content is in a div with id="content"
you could grab that...
success: function(data) {
$('#windowShop').html($(data).find('#content').html());
}
Try :
$.ajax({
url:'ajax/windowshop.php',
context:'#windowShop',
success:function(data){
$(this).append($(data).find('#idOfElement'));
}
});
You can use load
with a selector like this.
$('#windowShop').load('ajax/windowshop.php #windowShop');
精彩评论