开发者

fetch a div tag from return jquery ajax return value

I've got ajax working that returns whole HTML page.

I need to fetch a div tag which the class name is 'thisclass', this is a unique css class on that page.

I managed to use .find(), but then the string turned into object, how to solve this?

$.ajax({
      'url': '/test/',
      'type': 'POST',
      'data': {'age': age},
     开发者_C百科 '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
});


Try this code,

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


You can just use .html() on the object you got with .find().

Alternately, if you can manage to use an id="thisId" instead of a class="thisclass", then jQuery's .load() method has some special abilities, that would allow you do do something like

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜