2015-01-06 29 views
0

我不得不像下面我如何使用jQuery

var a = [ 
     { 
      "start":"2015-01-12T00:00:00.000Z", 
      "allDay":false, 
      "promotion_option":"banner" 
     }, 
     { 
      "start":"2015-01-13T00:00:00.000Z", 
      "allDay":false, 
      "promotion_option":"banner" 
     } 
    ]; 

數組後的JavaScript數組Laravel的控制器和I張貼陣列像下面這樣使用JQuery的Ajax

$.ajax({ 
    type: method, 
    url: url, 
    data: a, 
    success: function(res) { 
     var message = res.mesg; 

     if (message) { 
      $('.flash').html(message).fadeIn(300).delay(250).fadeOut(300); 
     }; 
    } 
}); 

在該對象我控制器,當我嘗試dd(Input::all()),它只是返回

array(1) { 
    ["undefined"]=> 
    string(0) "" 
} 

所以,我怎樣才能獲得的價值我發佈了什麼?

+0

http://stackoverflow.com/questions/8890524/pass-array-to-ajax-request-in-ajax看看這裏,也許,爲數據添加'{...}'將有助於 – demo

+0

發送一個像這樣的對象: '{A:}'。 – Jai

回答

2

你需要爲你在succecc回調喜歡用res.mesg傳遞數據的對象,並使用dataType:'json'

$.ajax({ 
    type: method, 
    url: url, 
    data: {a:a},//<== use object here 
    dataType:'json',// add this, as you are using res.mesg 
    success: function(res) { 
     var message = res.mesg; 
     if (message) { 
      $('.flash').html(message).fadeIn(300).delay(250).fadeOut(300); 
     }; 
    } 
}); 
1

嘗試JSON.stringify(a)將其轉換爲這樣的事情

"[{"start":"2015-01-12T00:00:00.000Z","allDay":false,"promotion_option":"banner"},{"start":"2015-01-13T00:00:00.000Z","allDay":false,"promotion_option":"banner"}]" 

注意它,它轉換爲後端的字符串。無論您收到HttpRequest中,你只需要記住這mind.Hope它有助於