Current location - Recipe Complete Network - Complete cookbook of home-style dishes - How to use ajax to validate a form? I hope there is code that can be directly quoted, thank you.
How to use ajax to validate a form? I hope there is code that can be directly quoted, thank you.
First, we must understand the meaning of ajax. Ajax is not a technology, but a mixed application of various means. Its principle is to request data directly from the Web server through the browser's XMLHttpRequest object (different browsers have different implementations, but they are all similar). The requested data will have various forms, and then it will be parsed and secondary processed by JS, and then the corresponding results will be displayed on the page. The advantage is that it can reduce the round-trip communication, and the disadvantage is that it improves the development difficulty and increases the code volume. I'll give you a simple example, with ASP.NET as the background, and then call it with js. The content logic of the example is also very simple, that is, input a string, then call the background method through ajax, and add a string after this string. The JS framework I use is jQuery. For more information about jQuery, please refer to related tutorials. If you have any questions, please contact me. ? jialiu830205@ 163.com

Backstage Asp.net(C#)

Create a generic handler? test.ashx

The content is as follows:

Create an html page with the following contents

Implementation results:

When you click Submit, the page does not refresh.

Of course, you can also use any other development tool or language, such as php or asp, or jsp. Just modify the background method, and then change the url parameter called in js to the corresponding path, and the same effect can be achieved.