简体   繁体   中英

find() Function return null in IE8 and IE7

I work on XMLResponse and try to find count value from xmlresponse.For that i write this code

this is my response in alert box

响应

cnt = Math.ceil($(xmlResponse1).find("count").text()/250);
alert(cnt);

it works in IE9 but return null ni IE8 and IE7.

Please help me. What Should have to do for solve this problem.

Thanks and Regards

The $() function is not suited for parsing XML. Use $.parseXML before wrapping the elements inside a jQuery object.

var cnt = Math.ceil($($.parseXML(xmlResponse1)).find("count").text()/250);
alert(cnt);

You can see it working in IE8 in this Fiddle

Or in easier to read way, caching the parsed XML document:

var xmlDOM = $.parseXML(xmlResponse1);
var cnt = Math.ceil( $(xmlDOM).find("count").text()/250 );

Updated demo

I think that text() does not work in ie7-8, try html():

cnt = Math.ceil($(xmlResponse1).find("count").html()/250);

Take a look at this question: jquery ie8 get text value = Object doesn't support this property or method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM