在加载内容ajax jquery时如何指定元素

在加载内容ajax jquery时如何指定元素,jquery,ajax,load,Jquery,Ajax,Load,如何在下面的代码中指定从pageurl中检索内容的元素 $(function () { $("a[rel='sort']").click(function (e) { //e.preventDefault(); /* if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax conten

如何在下面的代码中指定从pageurl中检索内容的元素

  $(function () {
     $("a[rel='sort']").click(function (e) {
         //e.preventDefault(); 
         /*  
    if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
    if commented, html5 nonsupported browers will reload the page to the specified link. 
    */

         //get the link location that was clicked
         pageurl = $(this).attr('href');

         //to get the ajax content and display in div with id 'content'
         $.ajax({
             url: pageurl + '?rel=sort',
             success: function (data) {
                 $('#content1').html(data);
             }
         });

         //to change the browser URL to 'pageurl'
         if (pageurl != window.location) {
             window.history.pushState({
                 path: pageurl
             }, '', pageurl);
         }
         return false;
     });
 });
使用jQuery.load()]事件

详情:


您可以使用
load()
函数,如下所示:

$('#content1').load(pageurl + '?rel=sort #elementToBeLoadedIn');

查看文档了解更多信息:

您必须在变量中获取响应,然后找到所需的内容

试试这个

$.ajax({url:pageurl+'?rel=sort',success: function(data){
    var content = $(data).find("#IDofYouContent");
    $('#content1').html(content);
}});

我仍然可以使用$([a[rel='sort'])。单击(函数(e){指定我刚才做的URL:)我的rep之前不够高。您在这里检索什么,success:function(data)。它是数据的json数组吗?
$.ajax({url:pageurl+'?rel=sort',success: function(data){
    var content = $(data).find("#IDofYouContent");
    $('#content1').html(content);
}});