gpt4 book ai didi

javascript - Laravel 5 如何解决使用 Bootstrap Form Validation Remote 验证唯一用户名时出现的错误

转载 作者:行者123 更新时间:2023-11-28 04:39:42 24 4
gpt4 key购买 nike

当我想使用 Boostrap FormValidation 远程验证唯一用户名时,出现错误。

以下是我在浏览器控制台中收到的错误:

主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响。如需更多帮助,请查看https://xhr.spec.whatwg.org/ .

未捕获的类型错误:b.success 不是函数

下面是我的代码

$('#user_form').formValidation({
framework: 'bootstrap',
fields: {
username: {
validators: {
notEmpty: {
message: 'Username is required'
},
remote: {
message: 'This Username has already been taken',
url: '/check_unique',
data: {
type: 'username'
},
type: 'POST'
}
}
},

Web.php

Route::post('/check_unique', 'UserController@unique');     

Controller

public function unique()
{
$user= User::where('username', Input::get('username'))->count();

if($user> 0) {
$isAvailable = FALSE;
} else {
$isAvailable = TRUE;
}

echo json_encode(
array(
'valid' => $isAvailable
));
}

最佳答案

实际上,Laravel 5 中有一种标准方法可以做到这一点(请参阅 https://laravel.com/docs/5.4/validationLaravel 5: Best way to validate form with Javascript )

如果你想按照自己的方式去做,那么:

  • XMLHttpRequest 是由 Bootstrap 或 jQuery 造成的,对此我们无能为力
  • Uncaught TypeError: b.success is not a function 意味着:

    • 也许您的请求只是没有附加?查看你的 php 日志
    • { success: $isUnique } 有效吗?

在我用谷歌搜索你的方法时,我没有找到任何东西,并得到了我给你的链接。

关于javascript - Laravel 5 如何解决使用 Bootstrap Form Validation Remote 验证唯一用户名时出现的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43886332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com