开发者

jquery: loading an html element with $.ajax or $.get methods

I would like to learn how to achive the following with the other two functions, or at least the ajax function.

$('#myDiv').load('index.php #content');

How would I load #content in the index.php file, into #myDiv on the current page with the $.ajax and $.get methods?

The url param doesn't seem to take a selector with any other ajax method then load.

this doesn't work...

$.ajax({ 
  url: 'index.php #content', 
  success: function(data) { 开发者_运维技巧
     $('#myDiv').html(data); 
  },
});


Remove #content from the URL and in the success function, try this:

$( '#myDiv' ).html( $( data ).filter( '#content' ).html() );

It would be nice if we could do it your way, but.... Maybe the jQuery team can implement this in the next release.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜