dongou3158 2014-04-12 16:27
浏览 149

CORS ajax请求出错

In php i do echo json_encode($dump);

If echo it out using php i get {"load":"0.64 0.58 0.52 2\/361 12978 ","procs":"8 "}

Than i make CORS Request using dataType:jsonp

$(function () {
        type: "POST",
        ContentType: 'application/json; charset=utf-8',
        url: '',
        dataType: "jsonp",
        success: function (response) {
        error: function (xhr, status, error) {

I get this error on the console:


  • 写回答

1条回答 默认 最新

  • dqfaom241360 2014-04-12 16:33

    You are dealing with JSON, not JSONP. dataType: "jsonp", should be dataType: "json",

    You can remove the data parameter entirely if your server outputs the correct content-type header for JSON (application/json).

    JSONP is a hack to work around the Same Origin Policy from before CORS was designed and implemented by browsers. CORS is the modern approach to making cross origin requests. You use it instead of JSONP.

    Both CORS and JSONP are technologies that must be supported by the server. doesn't appear to support either. You will have to modify the server if you want it to supply data in JSONP format or grant permission with CORS.

    Unrelated to your actual problem:

    You have no data parameter so you aren't sending JSON to to the server, remove the ContentType parameter. Since you aren't POSTing any data, you should probably be making a GET request, not a POST request.




  • ¥15 设计简单目录管理系统,要满足以下内容
  • ¥15 关于九十度混合耦合器信号分析问题
  • ¥15 Cesm如何关闭不用的模块呢
  • ¥15 vue2两层数据导出为excle
  • ¥15 有人能帮我做一下这个项目吗
  • ¥15 网络上传速率比下载速率高
  • ¥15 (标签-游戏|关键词-网页游戏)
  • ¥15 这个咋搞🥹可能需要手把手教
  • ¥15 接口和关键字的问题,多选
  • ¥15 yolov5s模型下载就卡住,没有运行结果