1 < Form name = " Registf " Method = " Post " Action = " # " >
2 < P > Registration Name: < Input type = " Text " Name = " User " / > <Span id = "check"> < / Span > < / P>
3 < P > Registration password: < Input type = " Password " Name = " PWD " / > < / P >
4 < P > < Input type = " Submit " Name = " SBM " Value = " Register " ID = " SBM " / > < / P >
5 < / Form>
6 < Button ID = " Test " > Ajax Testing < / Button>
The above is a very common form
We need to use ajax to check whether the name has been registered.
So:
1 VaR Xhr = {
2 Cxhr: New XMLHttpRequest () | New Activexobject ( ' Msxml2.xmlhttp ' ) | New Activexobject ( ' Microsoft. XMLHTTP ' ),
3 Request: Function (Method, URL, callback, postvars ){
4 Xhr. cxhr. onreadystatechange = Function (){
5 If (Xhr. cxhr. readystate ! = 4 ) Return ;
6 (Xhr. cxhr. Status = 200 ) ?
7 Callback. Success (xhr. cxhr. responsetext, xhr. cxhr. responsexml ):
8 Callback. Failure (xhr. cxhr. status );
9 }
10 Xhr. cxhr. Open (method, URL, True );
11 If (Method ! = ' Post ' | Method ! = ' Post ' ){
12 Postvars = Null ;
13 }
14 Xhr. cxhr. Send (postvars );
15 }
16 }
17
18 Window. onload = Function (){
19 VaR Callback = {
20 Success: Function (Responsetext, responsexml) {document. getelementbyid ( ' Check ' ). Innerhtml = Responsetext; alert (responsetext );},
21 Failure: Function (Statuscode) {alert ( " Failure " + Statuscode );}
22 };
23 Document. getelementbyid ( 'Sbm ' ). Onclick = Function (){
24 Xhr. Request ( ' Get ' , " Test. php " , Callback );
25 }
26 }
Behavior in FF:
Modify:
1 Window. onload = Function (){
2 VaR Callback = {
3 Success: Function (Responsetext, responsexml) {document. getelementbyid ( ' Check ' ). Innerhtml = Responsetext; alert (responsetext );},
4 Failure: Function (Statuscode) {alert ( " Failure " + Statuscode );}
5 };
6 Document. getelementbyid ( ' Test ' ). Onclick = Function (){
7 Xhr. Request ( ' Get ' , " Test. php " , Callback );
8 }
9 }
Run the following command:
That is to say, FF cannot make Ajax requests when submitting forms. I am studying the problems found today, but I do not know why. If there is any issue, I would like to advise.