来自ajax的WCF服务调用 [英] WCF Service call from ajax

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

问题描述

您好,我正在尝试使用本地地址从其他项目调用WCF服务。我在同一解决方案资源管理器中有两个项目。一个项目有服务,另一个是Web应用程序,我在javascript中使用Ajax来调用WCF服务。

以下是我的javascript代码,

Hello, I am trying to call WCF Service from other project using the local address. I have two projects in same solution explorer. One project has the services and the other is a web application where I am using Ajax in javascript to call the WCF Service.
Following is my javascript code,

function sclick() {
    alert("m here");
    $.ajax({
        type: "POST",
        url: "http://localhost:4780/Service1.svc/myfunction",
        contentType: "application/json; charset=utf-8 ",
        dataType: "json",
        success: success,
        error: fail
    })

}

function success(result) {
    alert(result);
    //alert("Success" + result.myfunctionResult);
}

function fail(result) {
    alert("Fail..... " + result.statusText + ": " + result.status);
}





流程转到成功功能,但我在结果对象中得到null。 ajax部分中的URL是我通过在浏览器中查看service1.svc文件获得的URL。

任何人都可以告诉我我哪里出错!



flow goes to success funtion but I get null in result object. URL in ajax part is the URL I got by viewing the service1.svc file in browser.
Can anyone please tell me where I am going wrong!

推荐答案

.ajax({
type: POST
url: http:// localhost:4780 / Service1.svc / myfunction
contentType: application / json; charset = utf-8
dataType:< span class =code-string> json
成功:成功,
错误:失败
})

}

function success(result){
alert(result);
// alert(成功+ result.myfunctionResult);
}

function 失败(结果){
alert( < span class =code-string>失败..... + result.statusText + + result.status);
}
.ajax({ type: "POST", url: "http://localhost:4780/Service1.svc/myfunction", contentType: "application/json; charset=utf-8 ", dataType: "json", success: success, error: fail }) } function success(result) { alert(result); //alert("Success" + result.myfunctionResult); } function fail(result) { alert("Fail..... " + result.statusText + ": " + result.status); }





流程转到成功功能,但我在结果对象中得到null。 ajax部分中的URL是我通过在浏览器中查看service1.svc文件获得的URL。

任何人都可以告诉我我哪里出错!



flow goes to success funtion but I get null in result object. URL in ajax part is the URL I got by viewing the service1.svc file in browser.
Can anyone please tell me where I am going wrong!


尝试:

Try:
success: function (msg) {
alert(msg.d);
}


这篇关于来自ajax的WCF服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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