How to validate a form's input from ajax page using jquery

后端 未结 2 1561
遥遥无期
遥遥无期 2021-01-26 04:14

There are two inputs in my form. The first input can be validated before an ajax function. The second input can\'t be validated. The second input comes from a page using ajax an

2条回答
  •  一整个雨季
    2021-01-26 04:48

    There's a few ways you can do this, however because I am on my phone I can't give you a detailed example.

    What I recommend for you to look into is sending the AJAX request as JSON data to your PHP file, you can then validate the JSON data within the PHP file and return a response to the front end accordingly.

    Within the PHP file you can return any value as a response, meaning that if you echo "success" or "true", you can see whether the data is what you are looking to receive from the user.

    I would highly recommend doing as much validation possible in the back end. It is a good habit to get in to as anything can be manipulated on the front end of a website.

提交回复
热议问题