JQuery's getJSON() not setting Accept header correctly?

ε祈祈猫儿з 提交于 2019-11-29 06:34:13

This is not a bug.

Since your call is cross-domain, your browser will not allow you to make XHR calls (same-origin policy). Internally, jQuery is working around this using the "<script> tag hack", to make the cross-domain call (this is the fundemental idea behind the JSONP data type). Since the call is made using the tag, it is simply not possible for jQuery to modify the accepts portion of the header.

jQuery works its magic by hiding these details from you, but unfortunately in this case you seem to be subject to the Law of Leaky Abstractions.

Without seeing your code (which might point us to an obvious solution,) can you try using the standard Ajax function and see if you get different results?

$.ajax({
  url: '/what.eva',
  dataType: 'json',
  data: '{}',
  success: callbackFunc
});

function callbackFunc(result) {
   alert(result);
} 

This is a bug which has been closed on the jquery website.

http://dev.jquery.it/ticket/6551

There does not appear to be a fix for this yet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!