( function( $ ) {
function CleanQueryString( query )
{
return encodeURI( query );
};
function ConcatData( settings )
{
settings.concatUrl = settings.googleUrl;
settings.concatUrl = settings.concatUrl.replace( "{key}", settings.googleApiKey );
settings.concatUrl = settings.concatUrl.replace( "{country}", settings.country );
settings.concatUrl = settings.concatUrl.replace( "{query}", settings.cleanQuery );
};
$.fn.GoogleSearchResult = function( options ) {
var settings = $.extend( {
query: null,
googleApiKey: "myapikey",
googleUrl: "https://www.googleapis.com/shopping/search/v1/public/products?key={key}&country={country}&q={query}&alt=json",
concatUrl: "",
country: "UK",
cleanQuery: ""
}, options);
return this.each( function() {
if( settings.query )
{
var $t = $(this);
settings.cleanQuery = CleanQueryString( settings.query );
ConcatData( settings );
alert( settings.concatUrl ); // This alerts the correct url and I've checked that it returns json
$.getJSON( settings.concatUrl, function( data ) {
alert("hi"); // This never alerts
$t.html( data );
});
}
return false;
} );
};
} )( jQuery );
$.getJSON を機能させることができません..何も返さない理由:
https://developers.google.com/shopping-search/v1/getting_started
送信した URL に直接アクセスすると、正しいデータが返されます。