2015-03-13 137 views
0

我在「.blade.php」文件中有以下代碼。無法從POST請求獲取響應。 Laravel和jQuery

$(document).ready(function(){ 
$("#ans_buttton").on('click', function(){ 
    $.post("http://localhost:8000/answer", {round: "{{$round}}", sno: "{{$sno}}"}, function(data, status){ 
     $("#answer").html(data); 
    }); 
}); 
}); 

並且路線如下。

Route::post('/answer', function(){ 
$round = Input::get('round'); 
$sno = Input::get('sno'); 
$ans = question::where('round', $round)->where('sno', $sno)->first(); 
echo "$ans->answer"; 
}); 

我得到一個500內部錯誤。 我錯過了什麼?

我是初學者。請幫幫忙!

+0

laravel 4或5? – itachi 2015-03-13 16:58:10

+0

@itachi Laravel 4.2 – 2015-03-13 17:00:04

回答

0

變化$ans = question::where('round', $round)->where('sno', $sno)->first();

$ans = question::where('round','=', $round)->where('sno','=', $sno)->first(); 

使用任何你想要的操作。

+0

好的..非常感謝! – 2015-03-13 18:09:10