1

我只是想进行一个简单的 ajax 调用来使用谷歌的 url 缩短器来缩短一个 url,但它没有返回任何数据。有人有想法么?

$.ajax({
                  type: 'POST',
                  url: "https://www.googleapis.com/urlshortener/v1/url",
                  contentType: 'application/json',
                  data: {longUrl: match},
                  dataType: 'json',
                  success: function(id){
                  $('#menu').html(id);
                  }
                });

我有一个 API 密钥,但我没有把它放在这里。而且您不需要使用该服务。

4

2 回答 2

1

使用 google 提供的 api 库来缩短 url,它在 php、java、.net 等中可用,

链接到 API 库 - http://code.google.com/apis/urlshortener/libraries.html

否则您的 ajax 需要为跨域 ajax 完成,请阅读此内容

于 2011-05-06T06:10:43.713 回答
0

您还必须发送您的 apikey。像这样:

           $.ajax({
              type: 'POST',
              url: "https://www.googleapis.com/urlshortener/v1/url?key=YOUR_API_KEY",

              data: {longUrl: match},
              dataType: 'json',
              success: function(id){
                 $('#menu').html(id);
              }
            });

希望这可以帮助。干杯

于 2011-05-06T05:55:02.613 回答