.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>
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的 xml 响应包含“类型”,但不包含“类型”...
Your xml response contains "Type", it does not contain "type"...
尝试使用filter()代替。查找通常会查找您使用它所针对的选择的子元素。
Try using filter() instead. Find generally finds child elements of the selection your using it against.
也许你也可以使用:
也许IE被差异语法弄乱了,这就是jQuery的网站描述该功能的方式。虽然我的第一个猜测也是你的方法..
Perhaps you could also use:
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..
这在 IE 中适用于我:
顺便说一句,jQUery 在解析 XML 时区分大小写,因此选择器必须是“Type”,而不是“type”。我必须将问题中给出的响应包含在根元素内,以使其有效 xml。它可以是任何唯一的标签,不一定是
This works for me in IE:
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>