guys i'm trying to work with ajax, i send the request to the server when a button clicked, then it's must return some HTML and show it, in the div with the id="formTag", but it's doesn't work can'i get some advice, Her is my code:
var ajaxRequest; // The variable that makes Ajax possible!
function ajaxFunction() {
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;
}
}
}
}
function getForm(objButton) {
ajaxFunction();
if (ajaxRequest.readyState == 4) {
document.getElementById("formTag").innerHTML = ajaxRequest.Response;
}
var buttonValue = objButton.value;
ajaxRequest.open("get", "get-form/" + buttonValue, true);
ajaxRequest.send();
}
function getForm(objButton) {
ajaxFunction();
ajaxRequest.onreadystatechange=function{
if (ajaxRequest.readyState == 4) {
document.getElementById("formTag").innerHTML = ajaxRequest.responseText;//property responseText contain data from server
}
}
var buttonValue = objButton.value;
ajaxRequest.open("get", "get-form/" + buttonValue, true);
ajaxRequest.send(null);//parameter null is necessary even you don't pass data
}
you could try this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.