Web方法返回JSON错误 [英] Web method returns JSON error

查看:128
本文介绍了Web方法返回JSON错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个自动填充文本框,根据我们在文本框中输入的内容,搜索工作正常。如果我在.cs文件中编写搜索方法工作正常。但同样我在.asmx文件中写道,引发了以下错误。



有什么问题?



JSON回复:



Hi all,

I've an autocomplete textbox, Searching is working fine based on what we type in the textbox. If i write the search method in the .cs file working fine. but the same i write in .asmx file, raising the following error.

What is the problem?

JSON response :

Message
    "Authentication failed."

StackTrace
    null

ExceptionType
    "System.InvalidOperationException"
"NetworkError: 500 Internal Server Error - http://localhost:51636/ProjectName/AutoComplete.asmx/SearchCities"

推荐答案

抛出此错误是因为您尝试调用另一个域的方法。出于安全目的,这是受浏览器限制的。

这里你可以通过 CORS (HTML5中的新功能)来实现这一点。

设置以下属性你的javascript。

This error is thrown because you are trying to call a method of another domain. this is restricted from browsers for security purpose.
here you can do this through CORS(new functionality in HTML5).
set following property in your javascript.


.support.cors = true ;
.support.cors = true;



从这里了解CORS ......

http://www.html5rocks.com/en/tutorials/cors/ [ ^ ]



其他解决方案是使用 jsonp dataType来调用你的服务。



这里是了解jsonp dataType的好链接。

http://www.jquery4u.com/json/jsonp-examples/ [ ^ ]


Learn about CORS from here...
http://www.html5rocks.com/en/tutorials/cors/[^]

And other solution is to use jsonp dataType to call your service.

here is good link to know about jsonp dataType.
http://www.jquery4u.com/json/jsonp-examples/[^]


请看一下这个链接。它对我有用。



http://stackoverflow.com/questions/23033614/asp-net-calling-webmethod-with-jquery-ajax-401-unauthorized [ ^ ]
Please take a look on this link. It worked for me.

http://stackoverflow.com/questions/23033614/asp-net-calling-webmethod-with-jquery-ajax-401-unauthorized[^]


这篇关于Web方法返回JSON错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆