- Mozilla Firefox 1.0 and above
- Netscape version 7.1 and above
- Apple Safari 1.2 and above.
- Microsoft Internet Exporer 5 and above
- Konqueror
- Opera 7.6 and above
NOTE: When we are saying that browser does not support AJAX it simply means that browser does not support creation of Javascript object XMLHttpRequest object.
Writing Browser Specific Code
Simple way of making your source code compatible to a browser is to use try...catch blocks in your javascript.<html> <body> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); }catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } } //--> </script> <form name='myForm'> Name: <input type='text' name='username' /> <br /> Time: <input type='text' name='time' /> </form> </body> </html>In the above Javascript code, we try three times to make our XMLHttpRequest object. Our first attempt:
- ajaxRequest = new XMLHttpRequest();
- ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
- ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");>
Most likely though, our variable ajaxRequest will now be set to whatever XMLHttpRequest standard the browser uses and we can start sending data to the server.
Next section will give you step by step explaination of AJAX work flow.
Không có nhận xét nào:
Đăng nhận xét