( 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"
} );