我正在尝试通过 ajax jquery函数进行REST GET调用。我要求通过JSON格式返回结果。相反,它是通过XML返回的,我不确定为什么。我的代码是问题吗?还有什么可以影响JSON请求?注意:如果网站有任何不同,该网站是https网站。
$.ajax(
{
type: 'GET',
url: "/sites/****/_api/web/Lists/getbytitle('ImageList')/Items",
headers: { "Accept": "application/json; odata=verbose" },
dataType: "json",
contentType: 'application/json; odata=verbose',
success: function (data) {
//do things
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//do other things
}
});
答案 0 :(得分:0)
除非您的端点被指定为 return Json,否则它不会。您使用的端点返回Xml,因为该特定URL旨在将其发回。您的代码是正确的,您正在连接的网址上的API显然是在发送网址所在的内容。
您的content-type
并不意味着它将返回 Json,它只是声明此类型是您应该期待的。
由于我们无法真正验证或测试任何数据,因此您应该查看: