【发布时间】:2020-06-16 04:58:29
【问题描述】:
我安装了一个带有身份验证的全新 Laravel 应用程序。我正在使用拉拉贡。登录、注册、重置密码页面工作正常。我为用户创建了一个配置文件控制器来编辑配置文件。但是,当通过 Ajax 提交表单时,它给了我一个Forbidden - You don't have permission to access / / /profile/edit_profile on this server.。
class ProfileController extends Controller
{
//
function index()
{
return view('profile.index');
}
function edit_profile(Request $request)
{
$txt_midname = $request->input('txt_midname');
$txt_firstname = $request->input('txt_firstname');
$txt_lastname = $request->input('txt_lastname');
$extname = $request->input('extname');
$user = Auth::user();
$user->firstname = $txt_firstname;
$user->midname = $txt_midname;
$user->lastname = $txt_lastname;
if ($user->save()) {
return 'ok';
}
}
}
这里也是路线:
Route::post('/profile/edit_profile', 'ProfileController@edit_profile')->name('edit_profile');
和视图:
$('#btn_update').on('click', function() {
var btn_text = $('#btn_update').text();
var txt_firstname = $.trim($('#txt_firstname').val());
var txt_midname = $.trim($('#txt_midname').val());
var txt_lastname = $.trim($('#txt_lastname').val());
var extname = $.trim($('#extname').val());
$.post(baseUrl + '/profile/edit_profile', {
'_token': token,
'txt_midname': txt_midname,
'txt_firstname': txt_firstname,
'txt_lastname': txt_lastname,
'extname': extname
}, function(data) {
if (data == 'ok') {
window.location.reload();
}
})
})
【问题讨论】: