首页 > 解决方案 > 不同机器中相同的 AJAX 请求以不同的格式返回

问题描述

我有以下问题:如果我在我的开发环境中发出 AJAX 请求,我会得到以下(缩写)原始结果:

{
  "id": 37988,
  "technique_id": 20,
  "task_area_id": 1,
  "task_area_name": "Gestao",
  "order": 3,
  "text": 437,
  "unscheduled": 0,
  "start_date": "17-10-2018",
  "hours": 4,
  "adjusted_hours": 4,
  "done_hours": 0,
  "duration": 1,
  "progress": null,
  "status": null,
  "worker": 53,
  "priority": 1,
  "parent": 236,
  "readonly": 0,
  "cancreate": 0
},

另一方面,当我在我的产品环境中调用它时:

{
  "id": "37988",
  "technique_id": "20",
  "task_area_id": "1",
  "task_area_name": "Gest\u00e3o",
  "order": "3",
  "text": "437",
  "unscheduled": "0",
  "start_date": "17-10-2018",
  "hours": "4",
  "adjusted_hours": "4",
  "done_hours": "0",
  "duration": "1",
  "progress": null,
  "status": null,
  "worker": "53",
  "priority": "1",
  "parent": "236",
  "readonly": "0",
  "cancreate": "0"
},

请注意,在我的 prod 上,int 值被转换为字符串。代码是一样的,数据库是一样的。

数据库调用也是一样的,在这两种情况下,数字都返回为 int,那么为什么在一种情况下保留 int 格式而在另一种情况下将其转换为字符串?

任何人都知道为什么会这样?

提前致谢!

标签: javascriptajax

解决方案


使用以下

JSON.stringify(obj);

推荐阅读