简体   繁体   English

表格POST后重定向

[英]Redirect after form POST

I am working on saving information submitted through a form to parse.com and then redirecting to an alternate page once complete. 我正在将通过表单提交的信息保存到parse.com,然后在完成后重定向到备用页面。 I have the POST working correctly but cannot find the easiest way to redirect to the new page. 我的POST工作正常,但是找不到重定向到新页面的最简单方法。 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';" 我有onclick =“ location.href ='appsuccess.html';” in the submit input but it would push sometimes before the POST. 在提交输入中,但有时会在POST之前推送。 Any suggestions? 有什么建议么? Thanks 谢谢

What about using 那使用呢

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

in the success function? 在成功的功能? ( How to redirect to another webpage in JavaScript/jQuery? ) 如何在JavaScript / jQuery中重定向到另一个网页?

Since you display a success message on your page, so I would suggest redirecting the user after a delay using setTimeout. 由于您在页面上显示成功消息,因此建议您在使用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. 这将导致站点在1.5秒的延迟后重定向。 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 有关setTimeout的文档: https : //developer.mozilla.org/zh-CN/docs/Web/API/WindowTimers/setTimeout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM