2014-02-28 78 views
0

我想在$ .ajax調用中傳遞2個參數。

這裏是我的代碼:

function getStatistic6() { 

var response; 
var allstat6 = []; 
var dstart = "01/01/2014"; 
var dend = "31/03/2014"; 
$.ajax({ 
    type: 'GET', 
    url: 'http://localhost:52251/Service1.asmx/Statistic_6_Entete', 
    data: "start='" + dstart + "'" + " end='" + dend +"'", 
    contentType: 'application/json; charset=utf-8', 
    dataType: 'json', 
    success: function (msg) { 
     response = msg.d; 
     for (var i = 0; i < response.Items.length; i++) { 
      var j = 0; 
      allstat6[i] = [response.Items[i].Date, response.Items[i].Piece, response.Items[i].Tiers, response.Items[i].AmoutHT, response.Items[i].AmountTTC, response.Items[i].Quantite]; 
     } 
     fillDataTable6(allstat6); 
     $('table').visualize({ type: 'line' }); 

    }, 
    error: function (e) { 
     alert("error loading statistic 6"); 
    } 
}); 
} 

我有一個錯誤: 「無效的JSON原始:結束= '31/03/2014'

帶有一個參數,我做的很好。

如何傳遞2個參數?

+1

使用數據作爲像JSON'{開始:DSTART,端:DEND}' – sofl

+0

我有這樣的錯誤消息 「無效JSON原始:01/2014」。 – Jayce

+0

嘗試使用'data:{「start」:dstart,「end」:dend}',另一個是無效的JSON。 http://jsonlint.com/ – JOBG

回答

0
data: {start: dstart, end: dend } 

編輯 給出與嘗試:

data: {"start": dstart, "end": dend } 
+0

我有這個錯誤消息「無效的JSON原語:01/2014。」 – Jayce

2

你可以把它作爲一個對象下

function getStatistic6() { 

    var response; 
    var allstat6 = []; 
    var dstart = "01/01/2014"; 
    var dend = "31/03/2014"; 
    $.ajax({ 
     type: 'GET', 
     url: 'http://localhost:52251/Service1.asmx/Statistic_6_Entete', 
     //pass it as an object, jQuery will serialize it for you 
     data: { 
      start: dstart, 
      end: dend 
     }, 
     contentType: 'application/json; charset=utf-8', 
     dataType: 'json', 
     success: function (msg) { 
      response = msg.d; 
      for (var i = 0; i < response.Items.length; i++) { 
       var j = 0; 
       allstat6[i] = [response.Items[i].Date, response.Items[i].Piece, response.Items[i].Tiers, response.Items[i].AmoutHT, response.Items[i].AmountTTC, response.Items[i].Quantite]; 
      } 
      fillDataTable6(allstat6); 
      $('table').visualize({ 
       type: 'line' 
      }); 

     }, 
     error: function (e) { 
      alert("error loading statistic 6"); 
     } 
    }); 
} 
+0

我有這個錯誤消息「無效的JSON原語:01/2014。」 – Jayce

+0

@Jayce則服務器端引起的問題......什麼是服務器端代碼 –

+0

「代碼」公共靜態列表 Helper_Statistic_6_Entete(DateTime的開始,結束日期時間) { ... }「代碼」 – Jayce

0

小修正,刪除的,並添加 「&」 之間每個值。

data: "start=" + dstart + "&" + " end=" + dend