简体   繁体   English

使用Jquery的Ajax函数处理来自ASP.NET Web服务的响应

[英]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.

相关问题 从ASP.NET Web API方法向jquery ajax发送间歇响应 - Sending intermittent response from ASP.NET Web API method to jquery ajax 使用Jquery对Asp.net Web方法进行Ajax调用 - Ajax call to Asp.net Web Method using Jquery jQuery从ASP.NET中的Web服务获取数据 - Getting data from web service in ASP.NET by jQuery 使用JQuery $ .AJAX调用调用ASP.NET函数 - Calling ASP.NET function using JQuery $.AJAX call 无法使用 asp.net web 服务将 ajax 标头值传递给我的 web 服务方法 - Not able to pass ajax headers value to my web-service method using asp.net web service 我在ASP.NET应用程序中使用ajax调用,并且从jquery Ajax调用中获取了整个HTML页面作为响应 - I'm using ajax call in ASP.NET application and I'm getting entire HTML page as response from jquery Ajax call 使用jquery / asp.net的ajax对话框中的值 - Value from ajax dialog using jquery / asp.net Javascript-处理来自Web服务的AJAX呼叫响应 - Javascript - Handling a AJAX call response from a web service 如何使用asp.net C#中的Ajax和Web服务使用数据库中的数据填充动态创建的下拉列表 - how fill the dynamically created dropdownlist with data from database using ajax and web service in asp.net c# 在ASP.NET上使用JQUERY重定向到asp.net页面。 - Redirect to asp.net page using JQUERY on asp.net button click from ajax modal extendar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM