I'm trying to access a script as JSON via AJAX, which works fine on Safari and other browsers but unfortunately will not execute in Chrome. It's coming with the following error:

拒绝从"*"执行脚本,因为其MIME类型("应用程序/json")不可执行,并且启用了严格的MIME类型判断.

以下是请求:

$.ajax({
    url: "http://some_url/test.json?callback=?",
    type: "GET",
    dataType: 'json',
    cache: true,
    success: function (data, status, error) {
      console.log('success', data);
    },
    error: function (data, status, error) {
      console.log('error', data, status, error);
    }
});

有人有解决办法吗?

推荐答案

By adding a callback argument, you are telling jQuery that you want to make a request for JSONP using a script element instead of a request for JSON using XMLHttpRequest.

JSONP is not JSON. It is a JavaScript program.

Change your server so it outputs the right MIME type for JSONP which is application/javascript.

(当您这样做时,不要告诉jQuery您期待JSON,因为这是矛盾的:dataType: 'jsonp').

Jquery相关问答推荐

将元素附加到每个函数 jQuery

如何使用 JQuery Select 没有特定子元素的元素

$.each() 与 for() 循环 - 和性能

如何 Select 具有特定文本的所有锚标记

什么是不使用 jQuery 的经验技术原因?

在jQuery中获取所有选定复选框值的最佳方法

使用 jQuery Validate 确认密码

Facebook 风格的 JQuery 自动完成插件

页面滚动后,jQuery可拖动在错误的位置显示助手

如何在 Backbone.js - Backbone.sync 或 jQuery.ajax 中保存整个集合?

如何在 JQuery UI 自动完成中使用 source:function()... 和 AJAX

JSON 到字符串变量转储

Select select2后触发动作

使用 jQuery DataTables 时禁用最后一列的排序

JQuery Ajax Post 导致 500 内部服务器错误

如何获得元素的正确偏移量? - jQuery

带有 jQ​​uery 的饼图

如何在 TypeScript 中获得 jQuery 自动完成功能?

如何使用 ID 变量在 jQuery 中 Select 元素?

使用 Chosen 插件更改 Select 中的 Select