简体   繁体   中英

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. What is the best way to do that?

php header (location: myurl).... doesn't capture the data-

echoing - javascript window.location.replace(myurl)... inserts the data, but doesn't redirect.

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.

You can use Angular's $location service in the callback, after the POST request is successfully completed:

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');
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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