Dashboard Cross-domain AJAX with jquery

前端 未结 5 1899
暖寄归人
暖寄归人 2020-12-19 10:21

Hey everyone, I\'m working on a widget for Apple\'s Dashboard and I\'ve run into a problem while trying to get data from my server using jquery\'s ajax function. Here\'s my

5条回答
  •  有刺的猬
    2020-12-19 10:58

    Interesting that it works in Safari. As far as I know to do x-domain ajax requests you need to use the jsonp dataType.

    http://docs.jquery.com/Ajax/jQuery.getJSON

    http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

    Basically you need to add callback=? to your query string and jquery will automatically replace it with the correct method eg:

    $.getJSON("http://example.com/getData.php?act=data&callback=?",function(){ ... });
    

    EDIT: put the callback=? bit at the end of the query string just to be safe.

提交回复
热议问题