I am new to Ajax and have a page that I am working on. I currently can use an ajax call to update my database. It works great. Also I am able to create a new listing.
I am trying to allow the user to update the page and stay on it as long as they are updating it.
If it is a new listing I want to create it in the database and redirect to a new page once it is saved.
Any help is greatly appreciated.
Here is what I am currently using. It works fine I just can't get it to go to a new page after the response from Ajax.
<script>
function SaveTrip() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("DEMO").value = xhttp.responseText;
var test = document.getElementById("DEMO").value;
if (test == "New Item Added!") {
alert(test);
window.open("http://www.pagename.com/program/Main.phpclienteditid=" + ClientID, "_self");
} else {
alert("Existing Item Has Been Saved!");
}
}
};
xhttp.open("POST", "SaveItem.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var ST1 = document.getElementById("T1").value;
xhttp.send("T1=" + ST1);
}
</script>