|
Java EE 6 example source code file (ajax.js)
The Java EE 6 ajax.js source codefunction getXMLObject() { var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+ } catch (e2) { xmlHttp = false // No Browser accepts the XMLHTTP Object then false } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers } return xmlHttp; // Mandatory Statement returning the ajax object created } var xmlhttp = new getXMLObject(); function ajaxFunction() { if(xmlhttp) { var username = document.getElementById("username"); var password = document.getElementById("password"); xmlhttp.open("POST","LoginServlet",true); //getname will be the servlet name xmlhttp.onreadystatechange = handleServerResponse; xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send("username=" + username.value + "&password=" + password.value); } } function handleServerResponse() { if (xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { document.getElementById("message").innerHTML=xmlhttp.responseText; } else { alert("Error during AJAX call. Please try again"); } } } function resetFunction() { document.getElementById("username").value=""; document.getElementById("password").value=""; document.getElementById("message").innerHTML=""; } Other Java EE 6 examples (source code examples)Here is a short list of links related to this Java EE 6 ajax.js source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.