When I try to execute an Ajax request with the data type 'text / xml; charset = utf-8 '... I get parsererror.
- Xml answer is valid xml
- The response header shows Content-Type 'text / xml; encoding = UTF-8 '.
- This is not a cross-domain request.
These three problems were answers in other questions of parserror.
My ajax looks like this:
$('#submitLogin2').click(function (e) { e.preventDefault(); var formData = $('#loginForm2').serialize(); var url = 'http://somewhere.com/Api2.0/Session_Create.aspx'; $.ajax({ url: url, type: "POST", dataType: 'text/xml; charset=utf-8', data: formData, contentType: 'application/x-www-form-urlencoded; charset=UTF-8', success: function (data) { $('#loginResult').html(data.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/ /g, ' ').replace(/\n/g, '<br />')); }, error: function (textStatus, errorThrown) { alert(errorThrown); alert(JSON.stringify(textStatus)); } }); });
And the answer is:
<Response><Error code='0'>Invalid User Name or Password</Error></Response>
Itโs great that the โtextโ request works ... but it would be nice to let Ajax parse the xml for me. Any ideas on how to make this work?
xml ajax xml-parsing
Brian rice
source share