1

I am working on saving information submitted through a form to parse.com and then redirecting to an alternate page once complete. I have the POST working correctly but cannot find the easiest way to redirect to the new page. Here is my code:

 <script>
        function validateForm() {
        Parse.initialize("1oFe8znPN2CwcEj14eIYaIOuxGtW35ZpmOazlG3H", "fJhaxIenhcwAdp66T14LKw4OukJ3lG6DLpkq1JVV");
        var TestObject = Parse.Object.extend("iOS");
var testObject = new TestObject();
  testObject.save({Phone: document.forms["appForm"]["phone"].value },{
  success: function(object) {
    $(".success").show();
  },
  error: function(model, error) {
    $(".error").show();
  }
});}

and

            <input type="text"  name="phone" id="contact_email"  class=" form-control input-email" placeholder="Phone Number">

            <input type="submit" id="sendingbtn" class="btn" value="Submit">

I had onclick="location.href='appsuccess.html';" in the submit input but it would push sometimes before the POST. Any suggestions? Thanks

2 Answers2

1

What about using

window.location.href = 'http://redirecturl/';

in the success function? (How to redirect to another webpage in JavaScript/jQuery?)

Community
  • 1
  • 1
Keith M
  • 1,199
  • 2
  • 18
  • 38
1

Since you display a success message on your page, so I would suggest redirecting the user after a delay using setTimeout. The timeout should be initiated after the post returns successfully. So, you should modify your success function to be:

function(object) {  
  $(".success").show();  
  window.setTimeout(function() {  
    location.href = "appsuccess.html";  
  }, 1500);  
}  

This will cause the site to redirect after a 1.5 second delay. You can adjust the timing as needed for the effect you want. Documentation on setTimeout: https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

BurningLights
  • 2,387
  • 1
  • 15
  • 22