开发者

How to call Yahoo Search Boss v2 using JQuery

Please would someone give me an example of how to call yboss (v2) using jquery. I've tried using getJSON and $.ajax methods passing the correct oauth values and signature but neither methods call the callback function. The same code worked fine with v1 of boss.

Here's an example of the url (requestStr) I pass to ajax:

    http://yboss.yahooapi开发者_运维知识库s.com/ysearch/web?callback=?&count=10&oauth_consumer_key=dj0yJmk9SFUzQno3ZnUwMHBaJmQ9WVdrOWNXRkRaa1Z2Tm1zbWNHbzlOek01TVRJeU1UWXkmcz1jb25zdW1lcnNlY3JldCZ4PWNk&oauth_nonce=7887075&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1317994276&oauth_version=1.0&q=horse&start=0&oauth_signature=lFVXgxkq79Tp5E5QeyEHdOfbASg=

When pasted into a browser (chrome) this returns the results expected. A payment account for using Yahoo Boss has been setup successfully in order to make calls to this api.

Thanks,

Rob

    $.getJSON(requestStr, function (response) {

    // never gets here

    });

    this doesn't work either:

    $.ajax({
      type: 'GET',
      url: requestStr,
      dataType: 'jsonp',
      success: function (response) {
      // never gets here
      }
    });


You're URL doesn't include a callback GET parameter. $.getJSON only requests JSONP if it finds that in the URL, so that's why that doesn't work. $.ajax, however, will supposedly add it to the URL if you specify the dataType as "jsonp", according to the jQuery docs. However, I see examples in the wild that include the callback in the URL regardless of specifying "jsonp" as the dataType. So, give it a shot.

As @Eonasdan suggested, check the responses you're getting in your console. If they're red, that means there's some sort of error, and in 99.9% of cases like these, it's due to same-origin policy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜