Call aspx web service/page from classic asp https:// site on the same server
I've got an ASP app running u开发者_开发知识库nder SSL that I want to extend by using JQuery/Ajax and thought I'd write the methods that are called by it in .NET, hosted on the same server. How do I set it up? Should it be within the SSL domain?
Here's an example. Decorate the web service with the [ScriptService]
attribute and then invoke it:
$.ajax({
type: 'POST',
url: '/WebserviceName.asmx/MethodName',
data: JSON.stringify({
Parameter1: 'foo',
Parameter2: 'bar'
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(json) {
// TODO: do something with the result
}
});
You could do the same with an ASPX page with PageMethods.
The only requirement is that the client is hosted on the same domain and it doesn't violate the same origin policy. So for example if the .NET page is hosted on HTTPS and your client page on HTTP you cannot send AJAX requests (that's considered as a violation of the same origin policy).
精彩评论