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

前端 未结 3 1863
情话喂你
情话喂你 2020-12-17 20:04

It looks like people have had issues with Accept headers in the past, but I\'m not sure my issue is related. Using jQuery 1.4.2, I\'m having trouble getting JSON with

相关标签:
3条回答
  • 2020-12-17 20:31

    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);
    } 
    
    0 讨论(0)
  • 2020-12-17 20:40

    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.

    0 讨论(0)
  • 2020-12-17 20:41

    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.

    0 讨论(0)
提交回复
热议问题