我試圖通過一個Ajax調用但陣列我送張貼關聯數組總是空的(鉻網絡調試)阿賈克斯後陣列(空)
我的Ajax調用
function getAssurance(passagers)
{
console.log(passagers);
var postdata = JSON.stringify({psg:passagers});
$.ajax({
dataType: "json",
url: rootUrl + "/b2c/searchAssurance",
data: postdata,
type: "POST",
success:function(result) {
console.log(result);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
}
數組是正確的,我的console.log()
我的路線
Route::post('/b2c/searchAssurance', '[email protected]');
我控制器
public function searchAssurance()
{
$search_data = Input::get('psg');
log::error(print_r($search_data,true));
echo "ok";
}
在哪裏我建立我的陣列
var valide = true;
var psgDetails = [];
if($("#country").val() == "-1")
{
valide = false;
}
if($("#state").val() == "0")
{
valide = false;
}
if($("#phone_0").val() == "0")
{
valide = false;
}
if(valide)
{
for(var i = 0; i<$("#nb").val(); i++)
{
var onePsg = [];
if(i==0)
{
onePsg['country'] = $("#country").val();
onePsg['state'] = $("#state").val();
onePsg['phone_0'] = $("#phone_0").val();
}
if($("#title_"+i).val() == "0")
{
valide = false;
}
if($("#name_"+i).val().length < 1)
{
valide = false;
}
if($("#lastname_"+i).val().length < 1)
{
valide = false;
}
if($("#dob_day_"+i).val() == "Day")
{
valide = false;
}
if($("#dob_month_"+i).val() == "Month")
{
valide = false;
}
if($("#dob_year_"+i).val() == "Year")
{
valide = false;
}
onePsg["title"] = $("#title_"+i).val();
onePsg['name'] = $("#name_"+i).val();
onePsg['lastname'] = $("#lastname_"+i).val();
onePsg['dob_day'] = $("#dob_day_"+i).val();
onePsg['dob_month'] = $("#dob_month_"+i).val();
onePsg['dob_year'] = $("#dob_year_"+i).val();
psgDetails.push(onePsg);
}
}
if(valide)
{
console.log(psgDetails);
getAssurance(psgDetails);
$("#assurance").show("slow");
$("#assuranceArrow").toggleClass('arrow-down arrow-up');
$("html, body").animate({scrollTop: $('#assurance').offset().top }, 200);
}
誰知道我做錯了什麼?
你怎麼稱呼getAssurance(),你如何注入passagers說法? –
首先返回Input :: all();並檢查所有數據是否到達控制器或不。 –