使用jquery-1.4.1.js拒绝访问 [英] access is denied using jquery-1.4.1.js
问题描述
我正在将VS2010与jquery-1.4.1.js版本一起使用,并且尝试访问WCF服务,并且在 jquery-1.4中收到奇怪的错误访问被拒绝" . 1.js ,页码为 4982
i am using VS2010 with jquery-1.4.1.js version and i try to access the WCF service and i get a strange error "Access is denied" in jquery-1.4.1.js at page number 4982
jquery-1.4.1.js:
jquery-1.4.1.js:
// Open the socket
// Passing null username, generates a login popup on Opera (#2865)
if ( s.username ) {
xhr.open(type, s.url, s.async, s.username, s.password);
} else {
xhr.open(type, s.url, s.async);
}
这是我的通话方式
function PostData() {
var webMethod = 'http://myservices/SomeService.svc/GetCount'
var parameters = "{'Id': '" + "1" + "'}"
$.ajax({
type: "POST",
url: webMethod,
data: parameters,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//$(divToBeWorkedOn).html(msg.d);
debugger
},
error: function (e) {
//$(divToBeWorkedOn).html("Unavailable");
}
});
}
可能是什么问题?我测试了我的wcf服务,它工作正常,我尝试通过asp.net连接并添加Web参考,只是为了看看是否有问题.
what might be the problem? i test my wcf service and it works fine, i try connecting through asp.net and add web reference just to see if there is any problem.
推荐答案
此行是不必要的:
contentType: 'application/json; charset=utf-8',
它告诉服务器您正在发送什么类型的数据,而不是您希望接收的数据,并且您实际上并没有发送任何数据.
It tells the server what kind of data you are sending, not what you expect to receive, and you aren't actually sending any data.
修改
似乎您正在另一个域上调用脚本.这违反了相同来源政策:您只能向同一域中的项目提出AJAX请求.有一种使用JSONP的解决方法,它需要服务器端支持.请参阅$.ajax
的文档,尤其是 JSONP dataType部分.
It seems that you are calling a script on another domain. This violates the same origin policy: you can only make AJAX requests to items on the same domain. There is a workaround using something called JSONP, which requires server-side support. See the documentation for $.ajax
, especially the JSONP dataType section.
这篇关于使用jquery-1.4.1.js拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!