What is the overall operation process of Ajax submitting form data to storage?
Ajax submit form data to the storage of the overall operation process, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article hope you can solve this problem.
* in the php project, when we want to write to the database, sometimes the code does not prevent sql injection, resulting in a variety of unpredictable errors *
This is a very simple registration page l I am submitting data in the form of ajax
The copy code is as follows:
RegisterForm
This is a test form!
User:
Ages:
Pass:
Addr:
Email:
Loading.
Body {text-align:center;}
.error {color:red;}
.tb {margin:0 auto;width:350px;height:200px;text-align:center;}
.tdleft {width:150px;text-align:left;}
$("# but") .click (function () {
Var name = $.trim ($("# name") .val ())
Var ages = $.trim ($("# ages") .val ())
Var pn = / ^\ dflowers /
Var addr = $.trim ($("# addr") .val ())
Var pass = $.trim ($("# password") .val ())
Var email = $.trim ($("# email") .val ())
Var reg = / ^ [a-zA-Z0-9 _] + @ [a-zA-Z0-9 _] + (\. [a-zA-Z] +) + $/ gi
If (name.length==0) {
Alert ("Please fill in your name carefully!"); return false
}
If (ages.length==0) {
Alert ("Please fill in your age!"); return false
}
If (! pn.test (ages)) {
Alert ("Please fill in the valid number!"); return false
}
If (pass.length==0 | | pass.length > 6) {
Alert ("Please fill in the password carefully!"); return false
}
If (addr.length==0) {
Alert ("Please fill in the address carefully"); return false
}
If (email.length==0) {
Alert ("Please fill in the email carefully!"); return false
}
If (! reg.test (email)) {
Alert ("email detection failed"); return false
}
Var send = {'name':name,'ages':ages,'pass':pass,'addr':addr,'email':email}
$.post ('_ process.php',send,function (data) {
If (data.res==-1) {
$("# result") .addClass ("error")
}
$("# result") .html (data.msg)
/ / $("form") [0] .reset ()
}, 'json')
})
$("# msg") .ajaxStart (function () {
(this) .fadeIn ()
}) .ajaxStop (function () {
(this) .fadeOut ()
})
File that receives the data submitted by ajax and does related processing
The copy code is as follows: