如何从javascript调用Web服务 [英] How do I call a web service from javascript
问题描述
假设我有一个网络服务 http://www.example.com/webservice。 pl?q = google ,返回文字google.com。我需要调用此Web服务( http://www.example.com/webservice.pl )来自带有参数(q = google)的JavaScript模块,然后使用返回值(google.com)进行进一步处理。
Say I have a web service http://www.example.com/webservice.pl?q=google which returns text "google.com". I need to call this web service (http://www.example.com/webservice.pl) from a JavaScript module with a parameter (q=google) and then use the return value ("google.com") to do further processing.
什么是最简单的方法去做这个?我是一个全新的JavaScript新手,所以任何帮助都非常感激。
What's the simplest way to do this? I am a total JavaScript newbie, so any help is much appreciated.
推荐答案
看一下众多的javascript库之一那里。我个人推荐 jQuery 。除了他们可以做的所有花哨的UI内容之外,它还有非常好的跨浏览器的AJAX库。
Take a look at one of the many javascript libraries out there. I'd recommend jQuery, personally. Aside from all the fancy UI stuff they can do, it has really good cross-browser AJAX libraries.
$.get(
"http://xyz.com/webservice.pl",
{ q : "google" },
function(data) {
alert(data); // "google.com"
}
);
这篇关于如何从javascript调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!