function ajaxLoad(method, URL, data, displayId) {
var ajax = null;
if(window.ActiveXObject){
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
ajax = new XMLHttpRequest();
}
else{
alert("Your browser doesn't support Ajax");
return;
}
method = method.toLowerCase();
URL += "?dummy=" + (new Date()).getTime();
if(method.toLowerCase() == "get") {
URL += "&" + data;
data = null;
}
ajax.open(method, URL);
if(method.toLowerCase() == "post"){
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
ajax.onreadystatechange = function() {
if(ajax.readyState==4 && ajax.status==200){
var ctype = ajax.getResponseHeader("Content-Type");
ctype = ctype.toLowerCase();
if(ctype.match("text/plain")){
ajaxCallback(ctype, displayId, ajax.responseText);
}
else if(ctype.match("text/javascript")){
eval(ajax.responseText);
}
delete ajax;
ajax = null;
}
}
ajax.send(data);
}
function ajaxCallback(contentType, displayId, responseText){
if(contentType.match("text/javascript")){
eval(responseText);
}
else {
var el = document.getElementById(displayId);
el.innerHTML = responseText;
}
}
ส่วนอันนี้ฟังก์ชั่นในการเรียกใช้ Code (PHP)
function SendMail(){
var idQ = document.getElementById("idQ").value;
var mailcus = document.getElementById("mailcus").value;
var mailcus2 = document.getElementById("mailcus2").value;
var mailother = document.getElementById("mailother").value;
var mailother2 = document.getElementById("mailother2").value;
var data = "stap2=yes&mailcus=" + mailcus + "&mailcus2=" + mailcus2 + "&mailother=" + mailother + "&mailother2=" + mailother2 + "&idQ=" + idQ ;
var URL = "Quotation_ajax.php";
ajaxLoad("post", URL, data, "");
}
คำถามคือ ในส่วนของการเรียกใช้ด้วยจาวาน่ะครับ พอดีผมเคยไปอ่านหนังสือมาเล่มนึง ขั้นตอนตรงนี้
var idQ = document.getElementById("idQ").value;
var mailcus = document.getElementById("mailcus").value;
var mailcus2 = document.getElementById("mailcus2").value;
var mailother = document.getElementById("mailother").value;
var mailother2 = document.getElementById("mailother2").value;