开发者

access is denied using jquery-1.4.1.js

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:

    // 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.pass开发者_运维百科word);
    } else {
        xhr.open(type, s.url, s.async);
    }

here is how i am calling

 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");
            }
        });
    } 

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.


This line is unnecessary:

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.


Edit

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜