laravel - 发送表单的问题-laravel中的路由js
问题描述
当我在子页面 url 上时,我在发送表单时遇到问题:
www.website.com - form works well
www.website.com/subpage - form works well
www.website.com/subpage/subpage - don't work
我有路由:
Route::post('apply-send', ['as' => 'apply', 'uses' => 'ApplyController@postSend']);
和我的js:
applySend: function() {
var $contactForm = $('#apply-form');
var $input = $('#apply-form input');
var $submitBtn = $contactForm.find(":submit");
var $alertPrototype = $('<div class="alert alert-dismissible text-center" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><div>');
counterTimeForm($contactForm, $input);
$contactForm.on('submit', function (e) {
e.preventDefault();
$alertInfo = $alertPrototype.clone();
$alertInfo
.addClass('alert-info')
.append('Trwa wysyłanie wiadomości...');
$submitBtn.replaceWith($alertInfo);
$.post('apply-send', $(this).serialize())
.done(function() {
$alertSuccess = $alertPrototype.clone();
$alertSuccess
.addClass('alert-success')
.append('<strong>Dziękujemy!</strong> Twoja wiadomość została wysłana.');
$alertInfo.replaceWith($alertSuccess);
$alertSuccess.after($submitBtn);
$contactForm.trigger('reset');
})
.fail(function() {
$alertDanger = $alertPrototype.clone();
$alertDanger
.addClass('alert-danger')
.append('Wystapił nieoczekiwany błąd. Zadzwoń lub spróbuj ponownie później.');
$alertInfo.replaceWith($alertDanger);
});
var $closeBtn = $('.alert .close');
});
},
我对这条线有疑问:
$.post('apply-send', $(this).serialize())
我不知道如何使表单在每个子页面上工作
解决方案
似乎您的 ajax 请求只是走错了路。所以,尝试设置绝对路径:
$.post('/apply-send', $(this).serialize())
推荐阅读
- powershell - 跳过 powershell 启动检查新版本
- python - 如何在 Python 中将字符串转换为十六进制?
- c++ - 如何对派生类说使用了哪些受保护的基类成员
- sql - 关于竞争对手和排名的 SQL 查询
- azure - 有没有一种简单的方法可以从 Azure VM 复制文件?
- oracle - 如何将 Oracle 11g impfile 导入到重新安装的 Oracle 11g?
- woocommerce - 获取在我的 woocommerce 商店的某个类别中发布的产品总数
- jenkins - 更改 docker-compose.yml 中的代理服务连接
- javascript - 在基本电子中成功运行,但在摩卡测试中出错
- eleventy - 11ty 将模板数据传递给语法高亮标签