【问题标题】:Problem receiving the response from a .post接收来自 .post 的响应时出现问题
【发布时间】:2020-01-31 19:54:10
【问题描述】:

我尝试了以下查询。

当我通过 devtools 看到答案时,我有以下信息:

{状态:true,信息:[,…],punitorios:[4786.6,4677.4],…} 状态:真 信息:[,…] punitorios: [4786.6, 4677.4]

但是我不能执行代码应该执行为真:

$.post('/buscarCuotas',{_token:_token,dni:dni},function(data){

    if(data.status === true)
    {
        .....

可能是什么原因造成的?我尝试在 .post 末尾添加“json”,但没有成功

【问题讨论】:

  • 响应实际上是布尔值类型,还是字符串?您可以考虑使用 data.status == true。
  • 嗨 Nicolas,这个问题还不清楚,如果你觉得用英文写作不方便,你可以在 es.stackoverflow.com 上提问。 Nicolas, la pregunta no es clara, es bastante confusa y no se identifica cual es el problema, ni que es lo que esperas conseguir。 Si no te sientes comodo preguntando en ingles, intenta usar SO en español.

标签: javascript jquery function response .post


【解决方案1】:

我认为如果您需要获取 JSON 数据,您需要序列化响应,或者为了使用更新的代码,您可以在可以使用的地方使用 fetch

    fetch('URL',
    method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(dataForTheServer))
    .then(response => response.json())
    .then(data => {
     if(data.status === true)
        {
      ...
     }
    }).catch(errorHandler)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2020-02-24
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多