Test if URL is accessible from web browser i.e. make sure not blocked by Proxy server

后端 未结 5 1034
日久生厌
日久生厌 2020-12-16 19:47

I am serving my website from mywebsite.com. I host images on flickr so all images are loaded in the user\'s browser via get requests to flickr. Many of my websites users a

5条回答
  •  半阙折子戏
    2020-12-16 20:25

    Flickr and Facebook both have APIs that support JSONP, so cross-domain isn't an issue. i.e. Here's a request that just echoes some dummy data from flickr's API.

    $.ajax({
      url: "http://www.flickr.com/services/rest/?jsoncallback=?",
      dataType: 'json',
      data: {method: "fickr.test.echo", format: "json", api_key: "02de950d65ec54a7a057af0e992de790"},
      success: callback
    });
    

    You can't reliably set error handlers on a jsonp reqest, so show a "loading" image until that success callback gets called. Set some timeout that will show an error message if the response doesn't come back fast enough.

提交回复
热议问题