簡體   English   中英

為什么Node應用程序中的HTTP POST請求在提交表單數據時需要刷新

[英]Why HTTP POST request in Node application require refresh while submitting form data

角度代碼

.state('studentInfo.newStudent', {
          url : '/new/student',
          templateUrl: 'students/new-student.html',
          controller : function($state, $http){
            this.saveStudent = function(student){
                $http({method: 'POST', url: `/studentInfo/new`, data: {student}}).then(function(){
                    $state.go('studentInfo');
      });

快遞代碼

app.post('/studentInfo/new', jsonParser, (request, response)=>{
   let students = mongoUtil.students();
   let newStudent = request.body.student;
   students.save(newStudent, (err, res) =>{
     if(err){
       res.sendStatus(400);
         }
     res.sendStatus(201);
      });
  });

我的問題是這些代碼可用於在提交Angular表單時保存數據。 但這需要刷新才能看到我的更新

http://localhost:8181/#!/studentinfo

我仍然可以提供一個狀態來繼續'studentinfo'。 進行哪些更改才能更新“ studentinfo”路由中的列表,以查看我當前保存的數據而無需刷新瀏覽器

如果您在發送響應和json數據時返回數據,並使用Angular解析它並在視圖上顯示。

如果成功,您必須在發送201的同時返回newstudent變量。

如果您要我編寫代​​碼,請在我的答案下方的評論中提及

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM