javascript - 接收来自 .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”,但没有成功
解决方案
我认为如果您需要获取 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)
推荐阅读
- python - 使用依赖项使用 Google Cloud Functions 部署 Python 函数时出错
- node.js - 在 GAE 中部署时出现 502 Bad Gateway
- javascript - 将更改推送到位桶
- powershell - Container 在尝试 Powershell 时在 CreateProcess 期间遇到错误
- java - 在 itext7 中更灵活地为表格绘制自定义边框
- python - Python返回列表列表以查看值是否存在
- python - 如何为每个用户 ID 重复一组日期?
- regex - 未转义的分隔符必须用反斜杠转义
- angular - 我正在使用引导程序和 css 以角度制作响应式表单,但我无法在其中设置提交按钮的宽度
- javascript - 如何使用 Phaser 3 中的函数绘制精灵?