Cross Domain Issue with implementing Google URL shortener API

后端 未结 3 764
我在风中等你
我在风中等你 2021-01-03 02:23

I am trying to implement the Google URL shortener API with the help of jQuery by making an AJAX call. I have done something like this:

$(function() {
    $(         


        
3条回答
  •  不知归路
    2021-01-03 02:46

    Indeed you are, I'm afraid. You can't make cross-domain ajax calls because of browser security.

    I know that Ext JS offer a ScriptTagProxy object which can do the work, but I'm not sure if jQuery has anything similar.

    An alternative would be to create a kind of "proxy" server-side script on your own host, which could accept parameters from your ajax call, make an HttpWebRequest or similar to googleapis.com and output the response to be picked up again by your ajax call. Then just modify your ajax url parameter to call your new proxy script instead of googleapis. In other words - let the server-side do the cross domain request.

提交回复
热议问题