kwk.stack
kwk.stack

Reputation: 553

extract specific html after ajax response

I am working on ajax and I am sending request to a page for data and that pahe contain header, footer, side menu(a full template page) and also the tables that I really want to grab without all other html in response like header footer etc.infact I want to target that only table with id selector only. the problem is that I am not allowed to remove any thing from the page like header footer etc so now I need help in it that how to grab that specific table with all the data I need in same table formate as I have to display it on dialog box. below is my ajax call

<script>
var firstDay = new Date();
var nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);
var nextWeek = nextWeek.getFullYear() + '/' + (nextWeek.getMonth()+1) + '/' +     nextWeek.getDate() ;

var url = 'x_PASSPORT_EXPIRED_DATE='+nextWeek+'&y_PASSPORT_EXPIRED_DATE='+nextWeek+'&z_PASSPORT_EXPIRED_DATE=BETWEEN&_search=1';

function showCustomer()
{
// fire off the request to ajax_stufflist.php
request = $.ajax({
    url: "ajax_stufflist.php?"+url,
    type: "post",
    success: function(data){

        alert($(data).find('table#gmp_stuff'));

        //$("#user_responses").html(data);
    },
    error:function(){
        alert("failure");
        $("#user_responses").html('error occurred');
    }
 });
}

I have user_response div to display all the data. I have all the response saved in data variable but I do not want to display that but need to extract that table first and then will display that table in user_response div.

as I cannot paste the response html here as there is too much code in it but the table I want to grab have an id="gmp_stuff". hope it would help you to show me the right way to proceed.

Upvotes: 2

Views: 778

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

If you mean you want to extract certain html content from your ajax response, then you can use .filter() for it, like:

..
success: function(data){
    var $response = $(data).filter("#gmp_stuff").html();
    $("#user_responses").html($response);
},
...

Upvotes: 4

Related Questions