( function( $ ) {
jQuery.support.cors = true;
function CleanQueryString( query )
{
return encodeURI( query );
};
$.fn.GoogleSearchResult = function( options ) {
var settings = $.extend( {
query: null,
googleApiKey: "something",
googleUrl: "https://www.googleapis.com/shopping/search/v1/public/",
concatUrl: "",
country: "UK",
cleanQuery: ""
}, options);
alert("im here"); // THIS ALERTS
return this.each( function() {
alert("q:" +settings.query); // THIS DOES NOT?
if( settings.query )
{
alert(":" + settings.query);
settings.cleanQuery = CleanQueryString( settings.query );
$.ajax({
dataType: "json",
async: false,
url: settings.googleUrl,
data: {
key: settings.googleApiKey,
country: settings.country,
q: settings.cleanQuery,
alt: 'json'
},
success: function( data ) {
alert( data );
return data;
},
error: function(xhr, status, error) {
alert("error " + status + " " + error);
}
});
}
} );
};
} )( jQuery );
this.each jquery プラグインを返す前に私のコードが壊れています。
私はそれを呼び出しています:
$.fn.GoogleSearchResult( {
query: "the apple ipad"
} );