Php Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException无消息Laravel 5.8和Ajax
我正在尝试在prospect系统中存储多封电子邮件。我正在用Laravel 5.8构建系统。我正在尝试使用AJAX请求放置电子邮件。并且不使用重定向返回页面,而是保持相同的模式 这是针对过去只能存储一封电子邮件的系统。但是一个用户说需要向客户存储多封电子邮件。现在,我正在尝试创建一个功能,在一个潜在客户中,您可以添加多封电子邮件,当用户发送建议时,将显示该潜在客户中存储的所有电子邮件 我需要使用AJAX请求来完成它。现在我尝试使用“POST”方法来继续我的功能,我将它放在我的路由、视图和AJAX请求中 这是我的路线Php Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException无消息Laravel 5.8和Ajax,php,laravel,laravel-5.8,Php,Laravel,Laravel 5.8,我正在尝试在prospect系统中存储多封电子邮件。我正在用Laravel 5.8构建系统。我正在尝试使用AJAX请求放置电子邮件。并且不使用重定向返回页面,而是保持相同的模式 这是针对过去只能存储一封电子邮件的系统。但是一个用户说需要向客户存储多封电子邮件。现在,我正在尝试创建一个功能,在一个潜在客户中,您可以添加多封电子邮件,当用户发送建议时,将显示该潜在客户中存储的所有电子邮件 我需要使用AJAX请求来完成它。现在我尝试使用“POST”方法来继续我的功能,我将它放在我的路由、视图和AJAX
Route::POST('prospect/email/save','ProspectEmailsController@store')->name('prospectmails.store')代码>
这是我的看法
<form id="emailModalProspect" method="POST">
@csrf
<input hidden name="prospect_id" id="prospect_id" type="text">
<div class="form-group mb-3">
<label class="form-control-label" for="prospect-email-name">{{ __('Nome') }}</label>
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-email-83"></i></span>
</div>
<input class="form-control" id="prospect-email-name" name="name" placeholder="Put the email owner" type="text">
</div>
</div>
<div class="form-group mb-3">
<label class="form-control-label" for="prospect-email-email">{{ __('Email') }}</label>
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-email-83"></i></span>
</div>
<input class="form-control" id="prospect-email-email" name="email" placeholder="Put the email" type="email">
</div>
</div>
<div class="text-center">
<button type="submit" id="save-email" class="btn btn-primary my-4 store-email">Store</button>
</div>
</form>
这是我的Ajax请求
$('.open-email-modal').on('click', function(e) {
e.preventDefault();
let p = JSON.parse($(this).attr('data-entity')); //the id of the prospect that i want to insert the emails
let modal = $('#emailModal');
let form = $('#emailModalProspect');
$('#prospect-email-name').val(p.name);
$('#prospect_id').val(p.id).change();
form.submit(function(e){
if(p.id) {
$.ajax({
url: "{{route('prospectEmails.store')}}",
type: "POST",
data : form.serialize() ,
dataType: "json",
success:function(data) {
if(data){
console.log(data); // here, in console, show a empty array like it "[]".
}
}
});
}
});
modal.modal({show : true});
});
现在我总是试图注册一封新电子邮件,显示以下消息:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
没有消息
在控制台中显示此错误
405号岗位(不允许使用方法)
奇怪的是,将数据存储在我的数据库中,但显示出来。如何显示此消息
我改为放方法。一开始它可以工作,但是显示令牌和我存储在URL中的内容。这不是我想要的
请使用
Route::any('prospect/emails/save','ProspectEmailsController@store')->name('prospectEmails.store');
或
而不是
Route::POST('prospect/emails/save','ProspectEmailsController@store')->name('prospectEmails.store')
请使用这样的路线
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
您的路线定义为prospect/emails/save
,但您正在发布到prospect
,这显然不是一条发布路线
按照正确的路线发送邮件,应该可以正常工作。将操作
添加到
应该可以做到以下几点:
<form action="{{ route('prospectEmails.store') }}" ...>
您可以分享您的请求吗?打开开发控制台查看控制台中的任何错误。我将编辑问题中的结果。但是在console.log(数据)中显示一个空数组“[]”,并显示结果:prospect:1 POST 405(不允许使用方法)您正在发送的头是什么,您正在发送csrf令牌吗?首先,我想是这样。选项和补丁路由是什么?你能给我解释一下吗?put和post的区别是什么?你能解释一下吗?太棒了,它工作得很好。现在我需要一个新问题,我不知道如何继续这个新问题:
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
<form action="{{ route('prospectEmails.store') }}" ...>