简体   繁体   English

AJAX GET请求不控制台记录响应,除CORB警告外没有错误

[英]AJAX GET request not console logging response, no errors except a CORB warning

I'm trying to get my data to show up as an object in the console. 我正在尝试将数据显示为控制台中的对象。 But it fails to do so and console logs "error". 但是这样做失败,并且控制台日志“错误”。 Only other thing that shows up in the console is a Cross-Origin-Read-Blocking warning. 控制台中显示的唯一其他内容是“跨域读取阻止”警告。 No errors though. 虽然没有错误。 How can I get my data to log on the console? 如何获取我的数据以登录控制台? Thanks 谢谢

 $.ajax({
    url: "valid url that returns JSON",
    type: "GET",
    dataType: "jsonp",
    jsonp: "callback",
    headers: { "Accept": "application/javascript;odata=verbose" },
    success: function (response) {
        console.log(response);
    },
    error: function (xhr, ajaxOptions, thrownError) {
          console.log(xhr);
          console.log(ajaxOptions);
          console.log(thrownError);
      }
});

Before the code above, I had "json" instead of "jsonp" and "application/json" instead of "application/javascript" as shown in the code below, but these returned a 401 Unauthorized error as well as a "CORS no access-control-allow-origin header" error. 在上面的代码之前,我有“ json”而不是“ jsonp”和“ application / json”而不是“ application / javascript”,如下面的代码所示,但是它们返回了401未经授权的错误以及“ CORS无法访问” -control-allow-origin标头”错误。 When I added jsonp, these errors went away and a CORB warning was left (shown in the code above). 当我添加jsonp时,这些错误消失了,并留下了CORB警告(如上面的代码所示)。 But my json data still nowhere to be found. 但是我的json数据仍然无处可寻。 Console logging ajaxOptions results in a "parsererror". 控制台记录ajaxOptions会导致“ parsererror”。 Console logging thrownError results in 控制台日志记录thrownError导致

Error: jQuery112409451109716420985_1542218619324 was not called 错误:未调用jQuery112409451109109420420985_1542218619324
at Function.error (jquery.min.js:2) at h.jsonp.b.dataTypes.(anonymous function).b.converters.script json ( http://kendo.cdn.telerik.com/2018.3.1017/js/jquery.min.js:4:28685 ) at Xb (jquery.min.js:4) at y (jquery.min.js:4) at HTMLScriptElement.b.onload.b.onreadystatechange (jquery.min.js:4)" 在Function.error(jquery.min.js:2)在h.jsonp.b.dataTypes。(匿名函数).b.converters.script json( http://kendo.cdn.telerik.com/2018.3.1017/ XScript的js / jquery.min.js:4:28685HTMLScriptElement.b.onload.b.onreadystatechange (jquery.min.js:4)的y(jquery.min.js:4)的(jquery.min.js:4) :4)”

$.ajax({
    url: "valid url that returns JSON",
    type: "GET",
    dataType: "json",
    jsonp: "callback",
    headers: { "Accept": "application/json;odata=verbose" },
    success: function (response) {
        console.log(response);
    },
    error: function (xhr, ajaxOptions, thrownError) {
          console.log(xhr);
          console.log(ajaxOptions);
          console.log(thrownError);
      }
});

This works for me 这对我有用

    $.ajax({ 
    type: 'GET', 
    url: 'my_url', 
    data: { key: 'value' }, 
    dataType: 'json',
    success: function (data) { 
        console.log(data);
    },
    error: function (xhr, ajaxOptions, thrownError) {
        console.log(xhr);
        console.log(ajaxOptions);
        console.log(thrownError);
    }
});

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

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