开发者

How to fetch elements from a page where its reference/link is provided in .js page

开发者 https://www.devze.com 2023-02-24 03:59 出处:网络
I\'m Using AJAX to dynamically fetch data from my php page (which contains html) and display it on another html page. Its fetching the whole data. But I want only the info under <table> and <

I'm Using AJAX to dynamically fetch data from my php page (which contains html) and display it on another html page. Its fetching the whole data. But I want only the info under <table> and <p id="recent">. How to do that? Here is the link to the page

HTML Pag开发者_如何学Ce where the call is made and result should be displayed

    <h3><a href="#" id="get">John</a></h3> 
    <div> 
        <p class="post">Result to be displayed</p> 
    </div>

AJAX code

   $.ajaxSetup ({
        cache: false
    });

    //  load() functions

    var loadUrl = "../load.php";
        $("#get").click(function(){
        $(".post")
            .html(ajax_load)
            .load(loadUrl, "language=php&version=5");
    }); 


This should help:

$('#get').click(function() {
  $.ajax({
    'url' : 'yoururl.php',
    'type' : 'GET',
    'success' : function(data) {
      $('p.post').html(data);
    }
  });
});

Hope that helps,
spryno724


Try changing your code to:

.load(loadUrl+" #recent", "language=php&version=5");

to get the <div id="recent"> or

.load(loadUrl+" table", "language=php&version=5");

for <table>.

jQuery's load function has a feature where you can define a selector to load data from as well as the page. http://api.jquery.com/load/


This will load just the <table> and <p id="recent-post"> from the other page.

$("#get").click(function() {
    var loadUrl = "../load.php?language=php&version=5";
    $(".post").load(loadUrl + ' table, #recent-post');
});
0

精彩评论

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