从Java脚本文件调用Web服务 [英] Calling Web Service from a Javascript file
问题描述
我正在尝试从一个简单的javascript文件调用Web服务的Web方法.该javascript文件可以添加到任何其他项目中,并且需要与数据库进行对话并获取一些数据.
我不想添加webservice.htc文件或具有Web参考,因为这将完全使上述目标无效.
我只想知道,有没有一种更好,更直接的方法可以通过JavaScript调用ASP.Net 3.5 Web服务?
如果是这样,请告诉我
谢谢,
拉姆
[删除电子邮件以避免垃圾邮件]
Hi,
I am trying to call a web method of a web service from a simple javascript file. This javascript file could be added to any other project and it needs to talk to database and fetch some data.
I do not want to add a webservice.htc file or have a web reference as this will totally nullify the above goal.
All I would like to know is, is there a better and straight forward way to call a ASP.Net 3.5 web service from a javascript?
If so, please let me know
Thanks,
Raam
[Email removed to avoid spam]
推荐答案
您可以通过ajax调用Web服务.
示例:
you can call web service by ajax.
Example:
var J = jQuery.noConflict();
function PreLoadMouseOverImages() {
var i = 0;
J.ajax({
type: "GET",
url: "webservice1.ashx",
success: function (msg) {
//msg is the response data
// you can do your work here.
}
});
}
搜寻"javascript xmlhttp".
googling for "javascript xmlhttp".
it might help you.
XMLHttpRequest()在我的域内有效.如果我尝试访问其他域URL,请求不会继续吗?
请让我知道
谢谢,
拉姆
XMLHttpRequest() works within my domain. If I try to access a different domain URL, the request isn''t going?
Please let me know
Thanks,
Raam
这篇关于从Java脚本文件调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!