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).
精彩评论