[英]Handling response from an ASP.NET web service using Jquery's Ajax function
I have this response coming from a ASP.NET web service 我有一个来自ASP.NET Web服务的响应
<string xmlns="http://Walkthrough/XmlWebServices/">
{"approverName":"","emailAddress":"","companyName":"ABC","address":{"streetAddress1":"12 BlahBlah","streetAddress2":"","state":"ON","zipCode":"","country":"SO","phoneNumber":""},"tabledata:"[{"vendorPart":"AAAAA","partDescription":"N/A","price":"0.00","quantity":"28"},{"vendorPart":"BBBBBBB","partDescription":"N/A","price":"0.00","quantity":"3"},{"vendorPart":"CCCCCC","partDescription":"N/A","price":"0.00","quantity":"25"}]}
</string>
which is being called with this jquery function: 这个jQuery函数正在调用:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "script",
success: function(msg)
{
alert("sucess")
},
error: function(e)
{
alert(JSON.stringify(e));
}
});
});
My first question is this, I was having 403 forbidden issues with this function but omitting the contentType changed that. 我的第一个问题是,此功能存在403个禁止的问题,但是省略contentType更改了它。 Then I was getting XML parsing issue and on a whim changing the dataType to script fixed that and gave me a response and I hit the success function.
然后我遇到了XML解析问题,一时兴起,将dataType更改为固定的脚本,并给了我响应,然后点击了成功函数。 Why did that work?
为什么这样做?
I also would like to know how I can print out this data, because trying to treat it as json won't work, neither does XML. 我也想知道如何打印此数据,因为尝试将其视为json无效,XML也不可行。
In chrome I receive this warning: 在Chrome浏览器中,我收到以下警告:
Resource interpreted as Script but transferred with MIME type text/xml: "http://www.webservice.com/blahblah.asmx/blahb123?tnWsGuid=TEST1&_=1366025879568."
The part appended to the end of this url is confusing me (after TEST1). 附加到此网址末尾的部分使我感到困惑(在TEST1之后)。 In the console I also get this error in chrome:
在控制台中,我也在chrome中收到此错误:
Uncaught SyntaxError: Unexpected token <
Firebug gives me: Firebug给了我:
SyntaxError: syntax error
[Break On This Error]
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://Walkthrough/XmlWebServices/">
{"approverName":"","emailAddress":"","companyName":"ABC","address":{"streetAddress1":"12 BlahBlah","streetAddress2":"","state":"ON","zipCode":"","country":"SO","phoneNumber":""},"tabledata:"[{"vendorPart":"AAAAA","partDescription":"N/A","price":"0.00","quantity":"28"},{"vendorPart":"BBBBBBB","partDescription":"N/A","price":"0.00","quantity":"3"},{"vendorPart":"CCCCCC","partDescription":"N/A","price":"0.00","quantity":"25"}]}
</string>
So basically now that the dataType is script I get some sort of response but still have no idea how to parse this data. 因此,基本上现在既然dataType是脚本,我会得到某种响应,但是仍然不知道如何解析该数据。 Preferably into a html table.
最好放入html表。
I hope you can help! 希望您能提供帮助! Thanks for reading!
谢谢阅读!
Edit: 编辑:
Here is a link to the header information logged by Firebug here 这是Firebug 在此处记录的标头信息的链接
your need to set datatype to json as the server send a json array. 您需要在服务器发送json数组时将数据类型设置为json。 see the datatype section here http://api.jquery.com/jQuery.ajax/
在此处查看数据类型部分http://api.jquery.com/jQuery.ajax/
我已经解决了这个问题,并成功地在IE中返回了数据集(由于Chrome和Firefox的异步问题,目前还不能在Chrome和Firefox上运行,我希望在托管此页面时可以解决这两个问题。我添加了$.support.cors = true;
就在ajax函数和我的新成功函数之前,正确地显示了数据,如下所示:
function(data, status, jqxhr) { xmlString = data;
alert(xmlString); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.