According to Laravel docs, they send a response with code 422 on a failed check:
If the incoming request was an AJAX request, a redirect will not be generated. Instead, an HTTP response with status code 422 will be returned to the browser containing a JSON representation of the validation error
So, you just need to process the response, and if the verification fails, add the verification message to the state, something like the following code fragment:
request = $.ajax({ url: "/user", type: "post", data: 'email=' + email + '&_token={{ csrf_token() }}', data: {'email': email, '_token': $('meta[name=_token]').attr('content')}, beforeSend: function(data){console.log(data);}, error: function(jqXhr, json, errorThrown) { if(jqXhr.status === 422) {
After that, in the "render" method, simply check if this.state.validationErrorMessage is set and a message is displayed somewhere:
render: function() { var text = this.state.submitted ? 'Thank you! Expect a follow up at '+email+' soon!' : 'Enter your email to request early access:'; var style = this.state.submitted ? {"backgroundColor": "rgba(26, 188, 156, 0.4)"} : {}; return ( <div> {this.state.submitted ? null : <div className="overall-input"> <ReactCSSTransitionGroup transitionName="example" transitionAppear={true}> <input type="email" className="input_field" onChange={this._updateInputValue} ref="email" value={this.state.email} /> <div className="validation-message">{this.state.validationErrorMessage}</div> <div className="button-row"> <a href="#" className="button" onClick={this.saveAndContinue}>Request Invite</a> </div> </ReactCSSTransitionGroup> </div> } </div> ) }
source share