0

I am getting HTML Table in jQuery Ajax response

$.ajax({ url: '/ajaxExecute.aspx?Fn=GETFEE', type: 'POST', context: document.body, cache: false, success: function (response) { alert(response); }); 

response contains following table

 <table border="1" id="tbl1" border="0" style="margin-left:30px;"> <thead> <tr> <th>fee_type</th><th>fee_amount</th><th>from_amt</th><th>to_amt</th><th>fee_percent</th><th>higher_of_two</th><th>max_capture</th><th>min_capture</th> </tr> </thead> <tbody> <tr> <td>0</td><td>5</td><td>0</td><td>0</td><td>0.00</td><td>0</td><td>0</td><td>0</td> </tr> </tbody> </table> 

I want only first row first td value i.e. 0

response.find('td').html(); 

in Console i am getting error Object response has no method 'find'

3 Answers 3

4

You can use .eq selector

$(response).find('tbody td:eq(0)').html(); 
Sign up to request clarification or add additional context in comments.

1 Comment

This is the answer you want as it'll only find the first td like you requested.
1

You need to wrap it using jQuery to create a jQuery reference.

The value returned by the ajax request is a string which does not have the jQuery method find() that is the reason for the error

$(response).find('td').html(); 

Comments

1

From the documentation :

Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.

The ajax function returns HTML as plain text. This means you must do this :

$(response).find('td').html(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.