承诺不会再次解决

时间:2020-05-16 15:25:21

标签: javascript ajax laravel es6-promise

我尝试一些一般的事情。第一次提交表单时,它可以正常工作,但第二次不能解决。我使用jquery.form.min.js。我认为,问题在于已经提交了表格,但我无法弄清楚。我也尝试过ajax发布。结果是一样的。

const makeRequest = formName =>
new Promise((resolve) => {
  $(formName).ajaxForm({
    headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    success: function(response) {
      //some code here
      resolve(response);
    }
  });
});


makeRequest('form')
    .then((res) => {
       //some code here
    });

HTML

<form id="form" name="form" method="POST" action="{{ route('product-confirmation') }}" class="needs-validation">
<div class="modal-body">
<div class="form-group">
   <label for="product_name">Title:</label>
   <input type="text" class="form-control" id="product_name" name="product_name" autocomplete="off" required>
 </div>
 <div class="form-group">
    <label for="product_description">Description:</label>
    <textarea class="form-control" rows="3" id="product_description" name="product_description"></textarea>
 </div>
 <div class="modal-footer justify-content-end">
 <button type="submit" class="btn btn-primary" form="form">Update</button>
 </div>

0 个答案:

没有答案