1

以下のコードの 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;
     });
 });
4

3 に答える 3

1

変数で応答を取得してから、目的のコンテンツを見つける必要があります

これを試して

$.ajax({url:pageurl+'?rel=sort',success: function(data){
    var content = $(data).find("#IDofYouContent");
    $('#content1').html(content);
}});
于 2012-12-17T09:32:29.920 に答える
1

jQuery.load()] イベントを使用

詳細: http://api.jquery.com/load/

$(function(){
    $("a[rel='sort']").click(function(e){
     pageurl = $(this).attr('href')+"?rel=sort #elementToBeLoadedIn";
    $('#content1').load(pageurl);
    .
    .
}
于 2012-12-17T09:29:05.093 に答える
0

load()次のように関数を使用します。

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

詳細については、ドキュメントをご覧ください: http://api.jquery.com/load/

于 2012-12-17T09:29:54.657 に答える