VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
Function validemail (e ){
Createxmlhttprequest ();
VaR ename = Document. getelementbyid ("ename ");
When learning Ajax, I wrote a piece of code:
<Form action = "" method = "Post">
<Table border = "1" width = 100%>
<Tr> <TD Height = 30>
Username: <input type = "text" name = "ename" id = "ename" onkeydown = "validemail (E);">
</TD> </tr>
<Tr> <TD Height = 50>
<Span id = "show"> </span> </TD> </tr>
</Table>
</Form>
<SCRIPT type = "text/JavaScript">
VaR url = "example6-2a.php? Ename = "+ ename. value;
XMLHTTP. onreadystatechange = callback;
XMLHTTP. Open ("get", URL, true );
XMLHTTP. Send (null );
}
Function callback (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
Document. getelementbyid ("show"). innerhtml = "server information:" + XMLHTTP. responsetext;
}
}
}
</SCRIPT>
However, when running on the current machine (firefox2.0 under FreeBSD), it does not get the expected effect and cannot be displayed when you enter characters (server information :****), accessing my server on another machine can work normally with IE or FF (3.0. I searched for it and did not get a satisfactory answer. There is an explanation that may partially explain the problem:
Compatibility with onkeyup in IE and Firefox
When creating a search function, the submit button is replaced by an image. In this case, it is easy to implement the function to automatically trigger the submission after the user enters a keyword and press Enter, however, Firefox later found that. the keycode does not catch a cold. After a Google click, the function key value returned by keycode in Firefox is not supported, as shown below:
In ie:
Keycode is supported, and which and charcode are not supported. Their values are undefined.
In Firefox:
Keycode is supported. Except for function keys, the value of other keys is always 0, and which and charcode are supported. The values are the same.
The solution is as follows:
View Source Code Javascript
function EnterSubmit(){
var _key;
document.onkeyup = function(e){
if (e == null) { // ie
_key = event.keyCode;
} else { // firefox
_key = e.which;
}
if(_key == 13){
s_submit();
}
};
}
I think it may be a problem with the browser version. If you have encountered a similar problem or know the cause, please explain. Thank you.