Есть слабый шанс, что можно попросить jQuery поменять это дело на ходу, указав в dataType "html jsonp":
multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml". Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.
Браузеры теряют гибкость (jquery, jsonp, mime type ('text/html') is not executable)?21.02.17 06:39 Автор: HandleX <Александр М.> Статус: The Elderman Отредактировано 22.02.17 00:05 Количество правок: 4
Раньше, чтобы обратиться на клиенте к стороннему сервису по его API, юзал JQuery JSONP сахар:
const srcURL = 'https://xxx.xx/api/rur';
$.ajax({
url: srcURL,
async: false,
jsonp: "callback",
dataType: "jsonp",
success: function( response )
{ и так далее
---
Сейчас в Хроме вылазит ошибка: "Refused to execute script from <...> because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled".
В самом деле, если посмотреть ответ сервера, там будут заголовки Content-Type: text/html и X-Content-Type-Options: nosniff, что заставляет браузер отказаться выполнить/распарсить JSON.
Как такое возможно обойти? Доступа к серверу со сторонним API не имею, изменить его заголовки нельзя.
Есть слабый шанс, что можно попросить jQuery поменять это дело на ходу, указав в dataType "html jsonp":
multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml". Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.
Да, глупость, но видимо у тамошних серверологов есть свои соображения насчёт нагрузки — они согласны отдавать API серверам (тот же PHP распарсит любую какаху), но сопротивляются клиентским браузерам.23.02.17 15:01 Автор: HandleX <Александр М.> Статус: The Elderman Отредактировано 23.02.17 15:04 Количество правок: 4
Попробовал "text jsonp" и "html jsonp", тогда хром выдаёт вот что: "XMLHttpRequest cannot load https://xxx.xx/api/rur. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access".
Первоначальный вариант позволял раньше делать кроссдоменный JSONP, что сейчас делать без понятия...