0

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>
nateyolles
  • 1,851
  • 5
  • 17
  • 23
  • What part isn't working? Is it going into the if statement? Is the alert being displayed?...Are there any errors in your console? – brso05 Aug 15 '16 at 20:49
  • `go to a new page`, do u mean redirection? – Iceman Aug 15 '16 at 20:50
  • There were no errors in the console. I looked on another page and someone suggested turning off my popups. That seemed to solve it. – M Allbrig Aug 15 '16 at 23:39

0 Answers0