Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery validation with ajax submit

   $(document).ready(function() {
       $('#formid').validate({
           rules: {
                fname : "required",
                mname : "required",
           },
           messages: {
               fname: "Please enter father name",
               mname: "Please enter mother name",
           },
           submitHandler: function(form) {
               var action="{{ route('personalinformation.store') }}";

               $.ajax({
                   url : action,
                   data:$(form).serialize(),
                   type : 'post',
                   success : function(result){
                       // alert(result.url);
                       if(result.status === "success"){
                           toastr.success(result.msg); // toastr used
                           setTimeout(function () {
                               window.location.href = result.url;
                           }, 2000)
                       }
                   },
                   error:function (response) {
                       let data = response.responseJSON.errors;
                       if (data) {
                           $.each(data, function(index, jsonObject) {
                               $.each(jsonObject, function(key, val) {
                                   toastr.error(val); // this wil show the error message
                               });
                               return false;
                           });
                       }
                   }
               });
           }
       });
   });
Comment

PREVIOUS NEXT
Code Example
Javascript :: read json using fs 
Javascript :: what is vanilla javascript 
Javascript :: js get node index 
Javascript :: vue toggle boolean on click 
Javascript :: array iteration 
Javascript :: how to convert array converted to string back to array javasccript 
Javascript :: custom react native product rating 
Javascript :: react 18 render 
Javascript :: promise.race polyfill 
Javascript :: javascript create object key from variable 
Javascript :: grepper extension firefox 
Javascript :: window.onscroll 
Javascript :: Conflicting peer dependency: react@18.0.0 npm WARN node_modules/react 
Javascript :: onchange value in hidden input 
Javascript :: javascript time script 
Javascript :: js create p element with text 
Javascript :: get the value of css pseudo properties js 
Javascript :: debouncing 
Javascript :: set background image URL jQuery 
Javascript :: jquery cget lineheight in pixels 
Javascript :: nextjs The engine "node" is incompatible with this module. 
Javascript :: how to check if text input has spaces javascript 
Javascript :: install bootstrap in react 
Javascript :: finding prime numbers in javascript 
Javascript :: base64 nodejs image 
Javascript :: get element by id inside first element by class in JavaScript 
Javascript :: javascript swap variables 
Javascript :: inline style react with true or false 
Javascript :: vowels Count js 
Javascript :: use font awesome in react native 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =