AngularJS - 表单参数不是通过使用 PHP 中的角度路由提交表单来传递的


AngularJS - Form parameters are not passed by submitting form using angular route in PHP

我在PHP应用程序中使用angularJS路由

我有以下情况:

我有一个名为仪表板的主页.php

我正在打开插入员工在 ng-View 插入员工页面有包含很少字段的表单。 和表单标签看起来像

<form action="" method="post"> 
     <!-- all fields -->
<input type="submit">
</form>

点击提交时,整个页面被重新加载,$_POST['paraName'] 显示未定义

我不希望重新加载整个页面。我想在 ngView 中打开带有参数的页面。

有8-10个参数,其中一个是员工照片

删除action="" method="post"属性,您不希望浏览器实际发送 POST 请求。相反,您订阅 onsubmit 事件并自行处理它:

<form ng-submit="save()"> 
    <!-- all fields -->
    <input ng-model="$ctrl.user.username" type="text"> 
    <input type="submit">
</form>

在控制器中,您将实现save方法并在那里执行任何需要做的事情,例如发出 AJAX POST 请求,并重定向到另一条路由:

function save() {
  // post xhr and redirect
  $http.post('/api/user', this.user)
    .then(response => response.data)
    .then(user => $location.path(`/user/details/${user.id}`))
  // or better with service
  users.save(this.user)
    .then(user => $location.path(`/user/details/${user.id}`))    
} 

引用:

  • ng提交 https://docs.angularjs.org/api/ng/directive/ngSubmit
  • $http.post https://docs.angularjs.org/api/ng/service/$http#post
  • $location https://docs.angularjs.org/api/ng/service/$location