someone kindly posted the following solution to consuming web services from this question at this link:
How to use jQuery to call an ASP.NET web service?
function InfoByDate(sDate, eDate){
var divToBeWorkedOn = '#AjaxPlaceHolder';
var开发者_StackOverflow webMethod = 'http://MyWebService/Web.asmx/GetInfoByDates'
var parameters = "{'sDate':'" + sDate + "','eDate':'" + eDate + "'}"
$.ajax({
type: "POST",
url: webMethod,
data: parameters,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$(divToBeWorkedOn).html(msg.d);
},
error: function(e){
$(divToBeWorkedOn).html("Unavailable");
}
});
}
It all goes well, and the data that I want is returned, BUT, I always get a warning from IE about 'This page is accessing information which is not under its control. This poses a security risk ... etc', and with Opera the information does not load because of a "Security violation" error.
How do I overcome this - I really need to stick with javascript because the code has to be placed in pages where I do not have access to the server programming facilities.
Thanks people.
You can only access web services from your local domain. You'll have to create a proxy locally that passes on the data returned from that remote web service. That is, if the web service is actually remote. If not, use a relative or absolute path to the ws.
精彩评论