2013-07-15 49 views
0

我越来越HTML表在jQuery的Ajax响应jQuery的获得首个TD值

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

响应包含如下表

<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> 

我想只有第一排第一个TD值即0

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

在控制台我得到错误对象响应没有方法'找到'

回答

3

您可以使用.EQ选择

$(response).find('tbody td:eq(0)').html(); 
+0

这是你想要的,因为它只会找到第一个TD像你要求的答案。 –

1

你需要用jQuery来包装它来创建一个jQuery引用。

由AJAX请求返回的值是不具有jQuery的方法find()即用于错误

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

的原因从the documentation的字符串:

返回HTML作为纯文本;包含的脚本标记在插入到DOM中时被评估。

ajax函数以纯文本形式返回HTML。这意味着你必须这样做:

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