簡體   English   中英

Ajax Post上的Laravel 500(內部服務器錯誤)

[英]Laravel 500 (Internal Server Error) on Ajax Post

我曾嘗試對自己的問題進行研究,但未能解決。 我正在嘗試單擊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);
    }

}
<meta name="token" content="{{ csrf_token() }}">
_token:$('meta[name="csrf-token"]').attr('content')

您的元標記名稱是token ,但是您正在尋找名為csrf-token的元標記。

如果存在meta ,則應查看網絡中的問題。

那是我的罪魁禍首:

像這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM