Ajax调用在本地返回json,但在服务器上运行时返回xml

Ajax call returning json locally but xml when run on the server

本文关键字:返回 服务器 运行时 xml json 调用 Ajax      更新时间:2023-10-06

我有一个ajax调用,它返回一些数据。当我通过visualstudio运行网页并在开发工具中查看结果时,我会看到{"d":{"__type":"WebService+MyObject等。然而,当我通过iis运行相同的代码时,ajax响应看起来是这样的:<?xml version="1.0" encoding="utf-8"?> <MyObject等。

我想我错过了一些设置,但我不知道它可能是什么。

为什么我在运行visualstudio时得到json,而在运行iis时得到xml。

尝试更改请求标头的内容类型。

Response.Headers.Add("Content-type", "text/json");
Response.Headers.Add("Content-type", "application/json");