Well im trying to get my form to post data to a php file and get back the result. For some reason its not calling mail.php, but instead it just puts all the post data in the current url like
somesite.com/index.php?id=value&id=value..etc
instead of
somesite.com/[B]mail.php[/B]?id=value&id=value..etc
here is the ajax code
var time_variable;
function getXMLObject() //XML OBJECT
{
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(); //xmlhttp holds the ajax object
function ajaxFunction() {
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
var towho = document.getElementById("towho");
var name = document.getElementById("name");
var email = document.getElementById("email");
var comment = document.getElementById("comment");
var subj = document.getElementById("subj");
var submitToDb = document.getElementById("submitToDb");
xmlhttp.open("POST","mail.php",true); //calling testing.php using POST method
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("towho=" + towho.value + "name=" + name.value + "email=" + email.value + "comment=" + comment.value + "subj=" + subj.value + "submitToDb=" + submitToDb.value); //Posting txtname to PHP File
}
}
function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById("result").innerHTML=xmlhttp.responseText; //Update the HTML Form element
}
else {
alert("Error during AJAX call. Please try again");
}
}
}
Any idea what is wrong?