开发者

Jquery Webservice in ASP.NET

I am working with ASP.NET 4.0 framework. In one web page, I have to call web service using Jquery as

     var serviceurl = 'http://www.websitename.com/webservicename';
         $.ajax({
                type: "POST",
                url: serviceurl + 'WebServiceName',
                data: "{'Parameters': '" + parameter+ "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    ShowAfterSuccess(msg);
开发者_StackOverflow中文版                },
                error: AjaxFailed
            });

It works fine, if i mention url as "http://www.websiteName.com" but when i put URL as "websitename.com" it doent call webservice. but it works well only in Google Chrome with "websiteName.com" I dont knw what is the issue with that....whether there is problem in my webservice calling or in URL..


You must ensure that you are not violating the same origin policy restriction. The best way to ensure this is to use relative urls:

var serviceurl = '/webservicename';

You must ensure that the domain hosting this javascript matches exactly the domain that you are sending your AJAX call to (including the protocol).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜