开发者

How to use remote web service by using Java Script on client side?

开发者 https://www.devze.com 2022-12-30 13:28 出处:网络
I\'ve spe开发者_运维技巧nt a week trying to use http://monitoring-gps.com.ua/aspservices/asptest.asmx methods on client side. How to do that?You can use jquery to do this -- look at http://encosia.com

I've spe开发者_运维技巧nt a week trying to use http://monitoring-gps.com.ua/aspservices/asptest.asmx methods on client side. How to do that?


You can use jquery to do this -- look at http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/


Use Ajax + Jquery: http://api.jquery.com/jQuery.ajax/

$.ajax( {
                                    type: "POST",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    url: "http://monitoring-gps.com.ua/aspservices/asptest.asmx/METHODNAME",                                                            
                                    data: "{'paramName':'" + ParamValue + "'}",
                                    success: function(data) { alert("That works;") }  
                                });


There are a few options here:

  1. Make a web reference using visual studio and then you can access it via javascript after you put a script service reference in the .aspx page http://msdn.microsoft.com/en-us/magazine/cc163499.aspx

  2. Use JQuery to make a ajax call. http://api.jquery.com/jQuery.ajax/


As far as I know, you can't call a cross domain web service via java script. If you try to call a web service within your web application in javascript, it will work. You need to find some workaround . This link should be helpful http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax

0

精彩评论

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