我已尝试对我的问题进行研究但未能解决问题。我点击了尝试Ajax POST。我读过最受欢迎的问题是由于csrf_token,但我相信我处理得当?
我一直收到这个错误:
POST http://example.com/refreshCalendar 500 (Internal Server Error)
这是我的代码......
我的master.blade.php文件顶部的csrf令牌的元标记
<meta name="token" content="{{ csrf_token() }}">
路线:
Route::post('/refreshCalendar', ['as' => 'refreshCalendar', 'uses' =>'Calendar@refreshCalendar']);
Js功能
function refreshCalendar(obj){
var month = obj.data('month');
var year = obj.data('year');
history.pushState(null, null, '/month/'+month+'/year/'+year);
var data = {
"month":month,
"year":year,
_token:$('meta[name="csrf-token"]').attr('content')
};
$.ajax({
type: "POST",
url: '/refreshCalendar',
dataType: 'html',
async:true,
data: data,
success: function(data){
$('#calendarHolder').html(data);
},
error: function(){alert("There was an error retrieving information");return false;}
});
}
我的控制器:
namespace App\Http\Controllers;
use DateTime;
use Illuminate\Http\Request;
class Calendar extends Controller
{
public function refreshCalendar(Request $request)
{
//Set data to $request
$data = $request->all();
return show($data['month'], $data['year'], true);
}
}