I have the following code, trying to get google’s 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 issue here is, when the datatype is just json, the request is made, but nothing is returned. when it is changed to jsonp, nothing happens at all. any ideas?
The JSON version doesn’t work because it’s a cross-origin call (see: Same Origin Policy). Does the Google URL shortener have a JSON-P API? It has to explicitly support it. (Also, JSON-P can’t be
POST; by its nature it’s aGET.)Update: Looks like they don’t support it yet, but there’s an open enhancement request.