首页 > 解决方案 > 接收来自 .post 的响应时出现问题

问题描述

我尝试了以下查询。

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

{status: true, info: [,…], punitorios: [4786.6, 4677.4],…} status: true info: [,…] punitorios: [4786.6, 4677.4]

但我无法执行代码应该执行为真:

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

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

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

标签: javascriptjqueryfunctionresponse.post

解决方案


我认为如果您需要获取 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)

推荐阅读