Showing error without page refresh

后端 未结 3 566
执念已碎
执念已碎 2021-01-17 04:10

I\'m making a comment feature for my website and need to make it so that after the person submits a comment (and it contains errors), it will show the error without refreshi

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 04:19

    For basic validations like empty fields or length of input box you can use jQuery validate plugin -- http://jquery.bassistance.de/validate/demo/ or write something of your own.

    You can use jQuery for a better AJAX/error handling. Check the documentation for jQuery AJAX here -- http://api.jquery.com/jQuery.ajax/

    $.ajax({
      url: "test.html", //URL to send the request
      success: function() {
        //do something. This is fired when your response is successful
      },
      error: function() {
        //highlight the field that has error or do something else here.
      }
    );
    

    Hope this helps :)

提交回复
热议问题