.each() 方法在 IE 中不起作用

发布于 2024-11-06 01:40:49 字数 1139 浏览 1 评论 0原文

在成功方法中,我无法循环遍历 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>

In success method i am unable to loop through xml response.

WebMethod is:

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

Success Method is

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

xml response is:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一笔一画续写前缘 2024-11-13 01:40:49

您的 xml 响应包含“类型”,但不包含“类型”...

Your xml response contains "Type", it does not contain "type"...

烟沫凡尘 2024-11-13 01:40:49

尝试使用filter()代替。查找通常会查找您使用它所针对的选择的子元素。

Try using filter() instead. Find generally finds child elements of the selection your using it against.

枫林﹌晚霞¤ 2024-11-13 01:40:49

也许你也可以使用:

$.each($(response).find('Type'), function(index, value) {
  alert('succes');
}

也许IE被差异语法弄乱了,这就是jQuery的网站描述该功能的方式。虽然我的第一个猜测也是你的方法..

Perhaps you could also use:

$.each($(response).find('Type'), function(index, value) {
  alert('succes');
}

Maybe IE is messed up with the difference syntax, this is how jQuery's website describes the function. Although my first guess would be your method aswel..

怂人 2024-11-13 01:40:49

这在 IE 中适用于我:

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

顺便说一句,jQUery 在解析 XML 时区分大小写,因此选择器必须是“Type”,而不是“type”。我必须将问题中给出的响应包含在根元素内,以使其有效 xml。它可以是任何唯一的标签,不一定是

This works for me in IE:

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

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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文