javascript
  • jquery
  • html
  • ajax
  • 2013-08-26 21 views 2 likes 
    2

    是否有可能在AJAX請求後添加一個jQuery選擇器到URL參數? 這是我的工作完美代碼:添加一個jQuery選擇器到URL參數

    $.ajax({ 
        type : "POST", 
        url : "load_page.php", 
        data : 'page=' + url, 
        success : function(msg) { 
         if (parseInt(msg) != 0)//if no errors 
         { 
          $content.fadeIn(200, function() { 
          $('#content').html(msg); 
    
          }); 
         } 
        } 
    }); 
    //load the returned html into pageContent 
    

    我知道,通過.load()(或link)這是可能的:

    $("# content'").load("demo_test.txt #sub.content"); 
    

    但有可能通過$('#content').html(msg);

    附加信息: 我想只能獲得<div id=」sub-content」>

    +1

    的' 「/你/ URL #selector」'語法只適用於'.load()'。 –

    回答

    4

    是的,只是其附加前的數據進行過濾。

    var $content = $("#content").empty(); 
    $("<div>").html($.parseHTML(msg)).find("#sub").appendTo($content); 
    
    +0

    你是我的英雄 – adho12

    相關問題