收到AJAX响应后,如何在Express.js模板中删除状态变量?

时间:2018-07-03 21:01:51

标签: javascript jquery json express templates

我的AJAX请求成功后,我会收到正确的数据,但是如果我想放置一个像invalidCode这样的状态变量,它会从快速路由的数据响应中返回。如何将其传递到快递模板?

function loadData(e) {
  e.preventDefault()
  var formData = {
    'code': $('input[name=code]').val()
  }
  // clear out old data before new request
  var data = {}
  // load streetview
  $.ajax({
    type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
    url: '/code', // the url where we want to POST
    data: formData, // our data object
    dataType: 'json', // what type of data do we expect back from the server
    encode: true
  }).done(function(data) {
    console.log(data)
    var title = data.title
    var invalidCode = data.invalidCode
  })
};

$('#form-container').submit(function(e) {
  loadData(e)
});

0 个答案:

没有答案