为什么我的页面在使用post时会继续尝试加载

时间:2016-08-18 15:50:19

标签: javascript jquery node.js

所以我使用条带来添加付款选项。但是,一旦我提交表单发布,页面就会继续尝试加载。我想知道是否有人能告诉我为什么会这样。感谢。

以下是带有

形式的HTML部分
<form action="" method="POST" id="payment-form">
  <span class="payment-errors"></span>
  <div class="form-row">
    <label>
    <span>Card Number</span>
    <input type="text" size="20" data-stripe="number">
    </label>
  </div>
  <div class="form-row">
    <label>
    <span>Expiration (MM/YY)</span>
    <input type="text" size="2" data-stripe="exp_month">
    </label>
    <span> / </span>
    <input type="text" size="2" data-stripe="exp_year">
  </div>
  <div class="form-row">
    <label>
    <span>CVC</span>
    <input type="text" size="4" data-stripe="cvc">
    </label>
  </div>
  <input type="submit" class="submit" value="Submit Payment">
</form>

这是server.js

app.post('/payments.html', function(req, res) {
  var token = req.body.stripeToken; // Using Express

  // Create a charge: this will charge the user's card
  var charge = stripe.charges.create({
    amount: 1000, // Amount in cents
    currency: "usd",
    source: token,
    description: "Example charge"
  }, function(err, charge) {
    if (err && err.type === 'StripeCardError') {
      // The card has been declined
    }
  });
});

0 个答案:

没有答案