加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Laravel 5将现有的验证用于AngularJS

发布时间:2020-12-17 07:12:06 所属栏目:安全 来源:网络整理
导读:嗨我在laravel 5现有验证中遇到了问题. 在我的控制器和请求中. class PostEmailRequest extends Request{/** * Get the validation rules that apply to the request. * * @return array */public function rules(){ return [ 'email' = 'required|max:255',
嗨我在laravel 5现有验证中遇到了问题.

在我的控制器和请求中.

class PostEmailRequest extends Request{
/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'email' => 'required|max:255',];
}}

它将返回电子邮件的验证作为示例.我想用angularjs做什么是我想要捕获验证并在我的前端表单上获取它.它不会重新加载页面.你对这个有什么想法吗?

我的应用程序中的表单将通过angularjs发送数据. $http post url“app / postPage”如果它的错误高于我的代码将$validation-> messages()发送到我的angularjs.

解决方法

你可以做以下.

>制作一个POST路由进行验证,让我们说myapp.com/validateEmail
>使用anuglarJS的$http请求将要验证的数据发送到此路由.让我们说
电子邮件
>验证数据并将验证对象作为JSON返回.您可以像这样发送JSON响应. JSON Responses from docs
>在angularjs控制器的范围模型中读取此JSON.在下面代码的success()中.

$http.post('/someUrl',{msg:'hello word!'}).
  success(function(data,status,headers,config) {
// this callback will be called asynchronously
// when the response is available
 }).
error(function(data,config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});

>根据HTML中的范围显示适当的错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读