.each() method not working in IE
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</Created开发者_C百科On>
<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>
Your xml response contains "Type", it does not contain "type"...
Try using filter() instead. Find generally finds child elements of the selection your using it against.
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..
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>
精彩评论