从返回jquery ajax返回值中获取div标记

时间:2010-12-06 07:06:06

标签: jquery ajax

我有一个返回整个HTML页面的ajax工作。

我需要获取一个div标签,其类名是'thisclass',这是该页面上唯一的css类。

我设法使用.find(),但后来字符串变成了对象,如何解决?

$.ajax({
      'url': '/test/',
      'type': 'POST',
      'data': {'age': age},
      'dataType': 'html',
      'success': function(data) {
       // data contains a whole page of HTML, I need the contents of a div tag
          which has css class .thisclass
});

2 个答案:

答案 0 :(得分:1)

您可以在使用.html()的对象上使用.find()

或者,如果您可以设法使用id="thisId"而不是class="thisclass",那么jQuery的.load()方法有一些特殊功能,可以让您执行类似

$("#placeToPutTheResult").load("http://example.com/page #thisId");

答案 1 :(得分:1)

试试这段代码,

$.ajax({
      'url': '/test/',
      'type': 'POST',
      'data': {'age': age},
      'dataType': 'html',
      'success': function(data) {
                        $("#yourid").html($(".thisclass",$(data)).html());
                 }
});
相关问题