用JavaScript读取Web服务数据 [英] Read webservice data in JavaScript

查看:95
本文介绍了用JavaScript读取Web服务数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是.Net中的一段代码,它从网络服务中读取数据:

Below is a piece of code in .Net, that reads data from a webservice:

string url = "http://localhost:48677/Service1.svc/GetDataSet1/FENCEGATE";
var webClient = new System.Net.WebClient();
string data = webClient.DownloadString(url);



现在我想做同样的事情JavaScript中的东西,但不知道该怎么做。感谢您是否可以分享您的经验。


Now I want to do the same thing in JavaScript, but don't know how to do it. Appreciate if you can share your experience.

推荐答案

您实际上并没有使用Web服务,只是通过URL获取HTTP响应,而不是使用任何HTTP命令。你确定你得到了你想要的结果吗?如果这是你想要的,你可以使用Ajax做同样的事情:

http: //en.wikipedia.org/wiki/Ajax_%28programming%29 [ ^ ]。



使用Ajax的一种便捷方法是使用jQuery Ajax:http://api.jquery.com/jquery.ajax/ [ ^ ]。



-SA
You don't really use a Web service, you are just get HTTP response by URL, not using any of HTTP commands. Are you sure you get the result you want? If this is really way you want, you can do the same using Ajax:
http://en.wikipedia.org/wiki/Ajax_%28programming%29[^].

One convenient way to use Ajax is using jQuery Ajax: http://api.jquery.com/jquery.ajax/[^].

—SA

最好的方法是使用一些JavaScript框架 - 比如jQuery ...



The best way is use some JavaScript framework - like jQuery...


.ajax({
type:' 获取'
url :' http:// localhost:48677 / Service1.svc / GetDataSet1 / FENCEGATE'
成功:< span class =code-keyword> function (data){
alert(data);
}
})
.ajax( { type:'Get', url:'http://localhost:48677/Service1.svc/GetDataSet1/FENCEGATE', success:function(data) { alert(data); } })





详情请见此处:http://api.jquery.com/jquery.ajax/ [ ^ ]


这篇关于用JavaScript读取Web服务数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆