2017-04-17 111 views
1

我正在使用jquery validator插件来调用ajax函数我正在使用远程方法来检查电子邮件已存在或不在我的数据库中,但当我使用ajax调用时出现错误。 这是我的验证函数内jquery验证使用远程来检查电子邮件是否已经存在或不存在?

"email": { 
       required: true, 
       email: true, 
       remote: "/adminuser/store" 

      }, 

这是我的路线

Route::post('/adminuser/store', 'Admin\[email protected]')->name('admin.storeadminuser'); 

这是我的控制器内

$email_exists = Admin::where('email',$request->email)->exists(); 
     //echo $email_exists; 
     if ($email_exists) { echo 'true'; } else { echo 'false'; } 
     exit; 

的错误是

jquery.min.js:4 GET http://birdys.app/adminuser/store?email=karthigamm1995%40gmail.com 404 (Not Found) 
 

回答

0

更改:

Route::post('/adminuser/store', 'Admin\[email protected]')->name('admin.storeadminuser'); 

Route::get('/adminuser/store', 'Admin\[email protected]')->name('admin.storeadminuser'); 

ajax()的默认方法是get和路线定义为post。因此请将其更改为get,然后重试。

或者在您的远程ajax调用中定义type: "post"

+0

它仍然显示404错误 – Karthiga

+0

是路线问题,我的路线是一组函数内部'路线::前缀(“管理员”) - > group(function(){Route :: post('/ adminuser/update/{id}','Admin \ AdminUserController @ update') - > name('admin.updateadminuser');});' – Karthiga

+0

可能是是对的 –

0

添加POST方法在偏远一样,

remote: { 
     url: "/adminuser/store", 
     type: "post", 
     data: { 
      email: function() { 
       return $("#email").val(); 
      } 
     } 
} 

Remote-method docs

+0

POST http://birdys.app/adminuser/store 404(Not Found) – Karthiga

+0

尝试'url:“adminuser/store”,'删除starti ng'/'来自URL –

+0

当我尝试它时显​​示无法加载资源:服务器响应状态为404(未找到) – Karthiga

相关问题