【问题标题】:Meteor HTTP call is different from jquery ajax?Meteor HTTP 调用与 jquery ajax 不同?
【发布时间】:2018-02-24 03:29:03
【问题描述】:

我在 Meteor HTTP 和 jQuery ajax 中有相同的调用。但是服务器的响应不同。

流星:

HTTP.call("POST", url, {
    params: data
}, function (error, result) {
  //My works....
})

jQuery:

$.ajax({
  "url": url,
  "method": "POST",
  "data": data,
  success: function(data_res) {
    //My works...
  }
})

我希望得到相同的结果,但 jquery 正确执行,而流星返回错误。

调用是否不相同?

【问题讨论】:

  • 在您的开发工具中使用network 选项卡,并比较两个请求。找出他们的区别

标签: javascript jquery http meteor


【解决方案1】:

在 Meteor 方法调用中,使用“数据”字段而不是“参数”,因为它是一个 POST 请求。 在 Meteor 中试试这个:

HTTP.post( URL, {data:dataToBePosted,headers:{key:value}}//if headers needed use headers field 
   ,function( error, response ) {

   if ( error ) {
      console.log( error );
   } else {
      console.log( response);
   }
});

【讨论】:

    猜你喜欢
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多