jQuery AJAX - JSONP 将文本转换为 JSON
jQuery AJAX - JSONP convert text to JSON
Expected Duplication 1
Expected Duplication 2
我在各种问题中搜索关于 JSONP 的正确解释,但仍然找不到。
例如,
我想使用 JSONP
进行跨域请求,响应格式为 text/plain
。有没有办法覆盖或重新格式化响应?即用 dataType: "jsonp"
解析 text/plain
响应
我总是得到错误,
Resource interpreted as Script but transferred with MIME type text/plain: "Some_url"
Uncaught SyntaxError: Unexpected identifier
有人可以向我解释一下 RestAPI 应该总是 return JSON 格式的结果吗?
I wanted to do a cross domain request using JSONP and the format of the response is text/plain.
您需要了解 JSONP 技术利用 <script>
标记来加载资源。响应应该是有效的 javascript 代码,看起来像这样:
callback_function({"some": "data", "in": "JSON format"});
所以你的问题的答案是否定的,你不能用HTML回应然后转换它,它只会产生你已经看到的错误。
Expected Duplication 1
Expected Duplication 2
我在各种问题中搜索关于 JSONP 的正确解释,但仍然找不到。
例如,
我想使用 JSONP
进行跨域请求,响应格式为 text/plain
。有没有办法覆盖或重新格式化响应?即用 dataType: "jsonp"
text/plain
响应
我总是得到错误,
Resource interpreted as Script but transferred with MIME type text/plain: "Some_url"
Uncaught SyntaxError: Unexpected identifier
有人可以向我解释一下 RestAPI 应该总是 return JSON 格式的结果吗?
I wanted to do a cross domain request using JSONP and the format of the response is text/plain.
您需要了解 JSONP 技术利用 <script>
标记来加载资源。响应应该是有效的 javascript 代码,看起来像这样:
callback_function({"some": "data", "in": "JSON format"});
所以你的问题的答案是否定的,你不能用HTML回应然后转换它,它只会产生你已经看到的错误。