如何通过jquery ajax调用将多个参数传递给WCF服务 [英] How to pass multilple parameters to WCF service through jquery ajax call

查看:93
本文介绍了如何通过jquery ajax调用将多个参数传递给WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够获得结果,如果我只在我单独运行WCF时调用WCF服务。那么WCF服务工作正常



这是一个实际的URL得到结果:

 http: //   localhost :57946 / MaterialIssueService.svc / MaterialServiceJson / GetMaterialIssued / 2015-01-25 / 2015-01-29 / 1/1  



这些是参数

/ 2015-01-25 / 2015-01-29 / 1/1



但是当我通过AJAX发出请求时,生成如下的HTTP请求。

 http: //   localhost:57946 / MaterialIssueService.svc / MaterialServiceJson / GetMaterialIssued ?{2015-01-25 / 2015-01-29 / 1/1}   





所以,我无法得到结果,我如何传递参数?



我尝试了什么:



 $( function (){
$(' #btnSubmit')。click( function (){
var params = {
< span class =code-string>' FromDate' 2015-01-01
' ToDate' 2015-01-29
' PageIndex' 1
' PageSize' 1

}
调试器;
$ .ajax({
url: http:// localhost:57946 / MaterialIssueService。 svc / MaterialServiceJson / GetMaterialIssued
类型: 获取
数据: JSON .stringify(params),
dataType: json
contentType: application / json; charset = utf-8
成功: function (数据){
if (data.status == 成功){
alert(< span class =code-string> 完成 );

} else {
alert( 数据库级别出错!);
}
},
错误:功能(ex){
调试器;
alert(ex.responseText);

}
});
});
});

解决方案

function (){


' #btnSubmit')。click( function (){
var params = {
' FromDate' 2015 -01-01
' ToDate' 2015-01-29
' PageIndex' 1
' PageSize' 1

}
debugger ;


.ajax({
url: http:// localhost:57946 / MaterialIssueService.svc / MaterialServiceJson / GetMaterialIssued
type: 获取
数据: JSON .stringify(params),
dataType: json
contentType: < span class =code-string> application / json; charset = utf-8,
成功:功能(数据){
if (data.status == 成功){
alert( 完成);

} else {
alert( 数据库级别出错!);
}
},
错误: function (ex){
调试器;
alert(ex.responseText);

}
});
});
});


I can able to get result ,if i called the WCF service only when i run the WCF alone.So WCF service is working fine

This a actual URL to get the Result :

http://localhost:57946/MaterialIssueService.svc/MaterialServiceJson/GetMaterialIssued/2015-01-25/2015-01-29/1/1


these are the parameters
/2015-01-25/2015-01-29/1/1

but when i make a request through AJAX,The HTTP request generating like below.

http://localhost:57946/MaterialIssueService.svc/MaterialServiceJson/GetMaterialIssued?{2015-01-25/2015-01-29/1/1}



So ,I'm not able to get a result ,How do i pass parameter ?

What I have tried:

$(function () {
           $('#btnSubmit').click(function () {
               var params = {
                   'FromDate': "2015-01-01",
                   'ToDate': "2015-01-29",
                   'PageIndex': "1",
                   'PageSize': "1"

               }
               debugger;
               $.ajax({
                   url: "http://localhost:57946/MaterialIssueService.svc/MaterialServiceJson/GetMaterialIssued",
                   type: "Get",
                   data: JSON.stringify(params),
                   dataType: "json",
                  contentType: "application/json; charset=utf-8",
                   success: function (data) {
                       if (data.status == "Success") {
                           alert("Done");

                       } else {
                           alert("Error occurs on the Database level!");
                       }
                   },
                   error: function (ex) {
                       debugger;
                       alert(ex.responseText);

                   }
               });
           });
       });

解决方案

(function () {


('#btnSubmit').click(function () { var params = { 'FromDate': "2015-01-01", 'ToDate': "2015-01-29", 'PageIndex': "1", 'PageSize': "1" } debugger;


.ajax({ url: "http://localhost:57946/MaterialIssueService.svc/MaterialServiceJson/GetMaterialIssued", type: "Get", data: JSON.stringify(params), dataType: "json", contentType: "application/json; charset=utf-8", success: function (data) { if (data.status == "Success") { alert("Done"); } else { alert("Error occurs on the Database level!"); } }, error: function (ex) { debugger; alert(ex.responseText); } }); }); });


这篇关于如何通过jquery ajax调用将多个参数传递给WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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