1

I have a table that gets sorted by a certain column when the user selects an option from the drop-down. It is a self-referencing PHP script that contains an IF clause for a GET request.

Since it is a self-referencing file, it returns the entire HTML content of the page, so I need a single div returned. The entire response returns fine, but jQuery find always returns null for any div.

Also, the response data always returns "string" even though I have specified html. I'm not sure if this is relevant or not.

This is what I have so far:

function sortTable()
{     
    var by=encodeURIComponent(document.getElementById("sort").value)
    $.ajax({
    type: "GET", 
    url: '/tasks?sort=', 
    data: by,  
    dataType: "html",
    success: function(data) {  
        var tmp = data;
        var test = $(tmp).find("sort-table");
        alert(test.html());


    },

    });
JJJ
  • 32,902
  • 20
  • 89
  • 102
user975206
  • 51
  • 2
  • 4

3 Answers3

0

That was work for me

$(data).filter('div.test');

here is link Use Jquery Selectors on $.AJAX loaded HTML?

Community
  • 1
  • 1
Qasi
  • 31
  • 4
0

I think you are missing something

var test = $(tmp).find(".sort-table");

or

var test = $(tmp).find("#sort-table");
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
0
var test = $(tmp).find("div.sort-table");

it will find divs with class sort-table

Rafay
  • 30,950
  • 5
  • 68
  • 101
  • Thanks, this worked for calling another div on the page, but for some reason did not work for the sort-table div. I switched it to a class and it's working great – user975206 Oct 03 '11 at 07:50
  • `find("sort-table")` will look for an element named `sort-table` but `find(div.sort-table)` will look for a div that has a class `sort-table` – Rafay Oct 03 '11 at 07:52