开发者

Weird xDomain issues with $.getJSON

I am trying to use Topsy for tracking some stats. I had a script that worked locally, that uses $.getJSON to get what I need from their api.

Now I have run into a problem after deploying I get origin not allowed I have tried just about everything I know to get their JSONP to interpret

the code that works locally

get_total = (trend, duration, callback) ->
  requests = []
  search_words = []
  if trend.total?
    callback(trend, trend.total)
  else
    for item in trend.search_terms
      search_words.push(item.term)
    keywords = search_words.join('+OR+')
    url = "http://otter.topsy.com/search.json?callback=test&q=#{keywords}&window=#{duration}&apikey=38A260E9D12A4908B1AF9184B691131"
    re开发者_开发知识库quests.push($.getJSON(url, (data) ->
        trend.total = data.response.total
    ))

    $.when.apply($, requests).then ->
      callback(trend, trend.total)

When I remove the param for &callback and add a ? I get parse errors and the json is still sent with a MIME type json rather than a script.

according to the Topsy API adding a callback is all you need to serve a script instead of json.

Topsy JSONP Refrence

Javascript (JSONP)

When an API request uses a Javascript response format, the response body will be a javascript function call that takes one parameter containing the response object. An HTTP Header Content-Type: application/javascript` will also be sent.

+-------------------------------------------------------------------------+
|   Name      |  Type    |  Description                                   |
+-------------+----------+------------------------------------------------+
|   callback  |  string  |  Javascript callback function name. (required) |
+-------------------------------------------------------------------------+


Try this url:

http://otter.topsy.com/search.js?callback=test&q=test&apikey=38A260E9D12A4908B1AF9184B691131

Note, i changed it from search.json to search.js

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜