开发者

parse javascript object returned from ajax as html

Result (data) looks like this:

&开发者_如何学编程lt;tr>
   <td>
      Something...
   </td>
</tr>

<div id="paging">1, 2, 3... </div>

This is ajax

...
dataType: "html",
success: function(data) {
    parse data...    
    $('#myDiv1').html(data1);
    $('#myDiv2').html(data2);
}
...

Is it possible to parse data so that data1 contains table row(s) and data2 contains div#paging content?

Thanks in advance,

Ilija


try..

var data1 = $(data).find('tr');
var data2 = $(data).find('div#paging');

edit:

as Guffa, mentioned in below comments, you cannot parse it if the html is broken in structure... but I suspected you got more than that codes... anyway, here's a demo


As the HTML code is not complete, it can't simply be parsed by the browser. You have to parse it manually.

For example:

var match = /(<tr>.+</tr>)\s*(<div.+</div>)/.exec(data)
var data1 = match[1];
var data2 = match[2];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜