.each()方法在IE中不起作用 [英] .each() method not working in IE

查看:550
本文介绍了.each()方法在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在成功方法中,我无法遍历xml响应.

WebMethod是:

Public Shared Function GetTypes(ByVal TypeID As Integer) As String
    Dim db As New DbManager
    Dim ds As New DataSet
    db.AddParameter("@TypeID", TypeID)    
    ds = db.ExecuteDataSet("GetTypes")
    ds.Tables(0).TableName = "Types"
    Dim jsSer As New System.Web.Script.Serialization.JavaScriptSerializer
    Return jsSer.Serialize(ds.GetXml())
End Function

成功方法是

SuccessMethod: function (response, that) {
       $(response).find('Type').each(function (index) {
       alert("called");
})
});

xml响应为:

<TypeID>12</TypeID>

<RecordID>5</RecordID>

<CreatedOn>2011-04-24T09:00:00+05:00</CreatedOn>

<Type>Here is type.</Type>

<TypeID>22</TypeID>

<RecordID>5</RecordID>

<CreatedOn>2011-05-08T09:30:00+05:00</CreatedOn>

<Type>Here is type.</Type>

推荐答案

这在IE中对我有效:

response = '<root>' + response + '</root>';
xmlDoc = $.parseXML(response);
$(xmlDoc).find('Type').each(function (index,val) {
   alert("called");
});

,顺便说一句,jQUery 在解析XML时区分大小写,因此选择器必须是类型",而不是类型".我必须将问题中给出的响应封装在根元素中,以使其有效为xml.它可以是任何唯一标记,不一定是<root>

and incidentally, jQUery is case-sensitive when parsing XML, so selector must be 'Type', not 'type'. I had to enclose the response given in the question inside a root element to make it valid xml. It could be any unique tag, not necessarily <root>

这篇关于.each()方法在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆