Ajax调用Web服务 [英] Ajax call to web service
问题描述
我们需要通过脚本(javascript,vbscript,jquery)与Web服务进行通信。我们在尝试与Web服务进行通信时遇到错误。从我读过的文章看来,这条线似乎需要添加到Web服务中:
We need to communicate with a Web Service via scripting (javascript, vbscript, jquery). We are getting an error trying to communicate with the Web Service. From the articles I have read it seems this line needs to be added into the Web Service:
[System.Web.Script.Services.ScriptService]
。事情是我们无法将其添加到服务中,因为它是软件附带的已发布网站。
我是否能够在没有该属性的情况下调用此服务?还有什么我可以用脚本语言来打电话吗?
我尝试了什么:
. Thing is we are not able to add this into service as it's a published site that comes with the software.
Will I be able to still call this service without that attribute? Is there anything else I can do to make the call using scripting language?
What I have tried:
<script type="text/javascript">
$(document).ready(function()
{
$.ajax
(
{
type: "POST",
url: "myurl/method",
data: "{Operator:'elizma',OperatorPassword:'test',CompanyId:'T',CompanyPassword:'test',LanguageCode:'AUTO',LogLevel:'ldNoDebug',EncoreInstance:'EncoreInstance_0',XmlIn:''}",
contentType: "application/json; charset=utf-8",
datatype: "json",
success: OnSuccessCall,
error: OnErrorCall
}
);
}
);
function OnSuccessCall(response) {
alert(response.d);
}
function OnErrorCall(response) {
alert(response.status + " " + response.statusText);
}
</script>
推荐答案
(document).ready(function()
{
(document).ready(function() {
.ajax
(
{
类型:POST,
url:myurl / method,
数据:{运营商:'elizma' ,OperatorPassword:'test',CompanyId:'T',CompanyPassword:'test',LanguageCode:'AUTO',LogLevel:'ldNoDebug',EncoreInstance:'EncoreInstance_0',XmlIn:''},
contentType: application / json; charset = utf-8,
数据类型:json,
成功:OnSuccessCall,
错误:OnErrorCall
}
);
}
);
函数OnSuccessCall(响应){
alert(response.d);
}
函数OnErrorCall(响应){
alert(response.status ++ response.statusText);
}
< / script>
.ajax ( { type: "POST", url: "myurl/method", data: "{Operator:'elizma',OperatorPassword:'test',CompanyId:'T',CompanyPassword:'test',LanguageCode:'AUTO',LogLevel:'ldNoDebug',EncoreInstance:'EncoreInstance_0',XmlIn:''}", contentType: "application/json; charset=utf-8", datatype: "json", success: OnSuccessCall, error: OnErrorCall } ); } ); function OnSuccessCall(response) { alert(response.d); } function OnErrorCall(response) { alert(response.status + " " + response.statusText); } </script>
这篇关于Ajax调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!