简体   繁体   English

Json收到错误400

[英]Json getting error 400

I am trying to get the json from a link page. 我正在尝试从链接页面获取json。

The links works perfect when I open into the browser 当我打开浏览器时,链接工作完美

here is the code I get an error 400 in the console. 这是我在控制台中收到错误400的代码。 However, If I paste this url in my browser I get the page, any ideas what can be? 但是,如果我将此URL粘贴到浏览器中,则会得到该页面,有什么想法吗? and how to fix? 以及如何解决?

$(document).ready(function () {
  $('#get-data').click(function () {
    var showData = $('#show-data');

    $.getJSON('http://example.com', function (data) {
      console.log(data);

     showData.html(JSON.stringify(data))

    });

    showData.text('Loading the JSON file.');
  });
});

json in the url: 网址中的json:

{
    "day": 0,
    "people": 0,
    "total": 22,
    "tests": []
}

Status Code:400 Bad Request 状态码:400错误请求

Using $.getJSON sends to the server that the client accepts application/json . 使用$.getJSON将发送到服务器的客户端接受application/json It could be that the webserver is checking for the accepted type, and since it can't serve JSON on the requested endpoint, it'll give back a 400 error. 可能是网络服务器正在检查接受的类型,并且由于它无法在请求的终结点上提供JSON,因此会返回400错误。 (which is an error made on the client side) (这是在客户端发生的错误)

We however can't say if this is the case for sure, since you didn't say which URL you're trying this on and what the URL is configured to send back on that endpoint. 但是,我们不能确定是否确实是这种情况,因为您没有说您要在哪个URL上进行尝试,以及该URL上配置为发送回该端点的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM