从调用ASMX jQuery的Web服务 [英] calling asmx web service from jQuery
问题描述
我不能够从jQuery函数调用Web服务(ASMX)。
I am not able to call web service(asmx) from jQuery function.
这是说在调用Web服务的拒绝访问错误。这是工作在dev和本地机器,但我得到同样的错误。
It is saying "access denied" error while calling web service. It is working in the dev and local machine but I am getting the same error.
下面是我的Ajax调用
Here is my ajax call
$.ajax({
type: "POST",
url: "http://server.com/calculator.asmx/calculus",
data: "{ 'userID': '" + $("#usrid").val() + "','password': '" + $("#password").val() + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
error: Error
});
我的Web服务
[WebService(Namespace = "http://www.company.com/webservices/calculus")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class calculator : System.Web.Services.WebService
{
[WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet=false, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public bool calculus(string userName, string password)
{// my code}
该错误是在的http://阿贾克斯。 googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js 功能
访问被拒绝的错误在e.username x.open(N,e.url,e.async,e.username,e.password):x.open(N,e.url,e.async);
The error is in http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js function and the "Access denied" error at e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);
我已经包括[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)与作为的 http://forums.asp.net/p/1570168/3935094.aspx 并没有能够解决的概率。任何一个可以帮助我关于这个。
I have included [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] with the class as shown in http://forums.asp.net/p/1570168/3935094.aspx and not able to fix the prob. Can any one please help me regarding this.
感谢您
推荐答案
JSONP 是一个可行的办法,以解决该同源策略(又名跨站点脚本或XSS)的限制。它配备了自己的一套(例如,它只能用GET模式请求)的挑战,所以它肯定不是万能的。但它可能是值得你花时间给它看看。有一个像样的数目吧贴子计算器,它应该帮助您开始。
JSONP is a possible way to workaround the "same origin policy" (aka cross-site-scripting or XSS) limitations. It comes with its own set of challenges (for example, it works only with GET-mode requests), so it's certainly not a panacea. But it's probably worth your time to give it a look. There's a decent number of stackoverflow postings about it, which should help you get started.
这篇关于从调用ASMX jQuery的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!