我测试了一些简单的Ajax请求,我收到错误代码500,而试图与响应控制器 内部服务器错误500简单的jQuery Ajax请求Laravel ..错误代码:500
我web.php文件
This one works fine
//Route::get('/test', function() {
// return "i am a success get";
//});
I cannot seem to get this one to work
Route::get('/test', '[email protected]');
我的控制器
class shoppingCartController extends Controller
{
public function testfunction(Illuminate\Http\Request $request)
{
//
// if ($request->isMethod('post')){
// return response()->json(['response' => 'This is post method']);
// }
//
// return response()->json(['response' => 'This is get method']);
//
return 'test';
}
}
而且我的jQuery
$(document).ready(function(){
$("button").click(function(){
$.ajax({url: "test", success: function(result){
$("#div1").html(result);
}, error: function(xhr){
$("#div1").html(xhr.statusText + " " + xhr.status);
}
});
});
});
它工作没有ajax? – n00dl3
你的AJAX调用使用什么方法?如果它使用'POST',那么你会得到一个错误。如果您在浏览器中使用开发工具,您将能够看到实际的错误消息。 – James
使用萤火虫看到实际的错误讯息,并在这里发布。在ajax url上添加'/'使其成为'/ test'。它工作吗? –