简体   繁体   English

将数据提交到数据库后重定向到新页面的最佳方法? 角/ PHP的/ MySQL的

[英]Best way to redirect to new page after submitting data to db? angular/php/mysql

After a successful angularjs form submission to a MySQL db using php I want to send the user to a different page. 使用PHP成功将angularjs表单提交到MySQL数据库后,我想将用户发送到其他页面。 What is the best way to do that? 最好的方法是什么?

php header (location: myurl).... doesn't capture the data- php标头(位置:myurl)...。无法捕获数据,

echoing - javascript window.location.replace(myurl)... inserts the data, but doesn't redirect. 回显-javascript window.location.replace(myurl)...插入数据,但不重定向。

Assuming you're submitting the form through AngularJS, it's better to handle this redirect from the Angular side, rather than trying to get the PHP redirect working with an AJAX request. 假设您要通过AngularJS提交表单,最好从Angular端处理此重定向,而不是尝试使PHP重定向与AJAX请求一起使用。

You can use Angular's $location service in the callback, after the POST request is successfully completed: 成功完成POST请求后,可以在回调中使用Angular的$location服务:

app.controller('TestCtrl', function( $http, $location ){
  var req = {
    method: 'POST',
    url: 'http://example.com',
    data: { test: 'test' }
  };

  $http(req).then(function(){
    // this is executed after the request is completed successfully

    $location.path('/success-page');
  });
});

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

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