且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过jquery ajax调用将多个参数传递给WCF服务

更新时间:2023-10-25 22:28:04

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: 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); } }); }); });