Why does "data type: jsonp" not work?

I have the following code trying to get google url shortener to work.

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

The problem here is that when the data type is only json, the request is executed but nothing is returned. when it is changed to jsonp nothing happens at all. any ideas?

+3
source share
1 answer

The JSON version does not work because it is a cross origin call (see Same origin policy ). Does Google's shortened URL have a JSON-P API? He must clearly support him. (Also, JSON-P cannot be POST, by its nature it is a GET.)

: , , .

+6

All Articles