我正在开发一个简单的 eBay jQuery 插件。它成功地拨打了电话。它返回一个结果。但是,当它尝试查找我的回调函数时,我得到“未捕获的 ReferenceError:_cb_findItemsByKeywords 未定义”。
(function( $ ){
$.fn.ebay_jQuery = function( options ) {
var settings = $.extend({
rootURL : "http://svcs.ebay.com/services/search/FindingService/v1",
operationName : "findItemsByKeywords",
serviceVersion : "1.0.0",
securityAppName : "myApp",
globalID : "EBAY-US",
responseFormat : "JSON",
callback : "_cb_findItemsByKeywords",
keywords : "religious%20book",
entriesPerPage : "20"
}, options);
var html = [];
// Parse the response and build an HTML table to display search results
var _cb_findItemsByKeywords = function(root) {
var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
if (null != title && null != viewitem) {
html.push('<div class="box item-box" style="position: absolute; opacity: 1; top: 0px; left: 240px; ">'+
'<div class="item">'+
'<div>'+
'<div class="goods-pic">'+
'<a href="' + viewitem + '" target="_blank">' +
'<img src="' + pic + '" border="0">'+
'</a>'+
'</div>'+
'<p class="item-title" style="margin-top: 10px;">'+
'<a href="' + viewitem + '" target="_blank">' + title + '</a>'+
'</p>'+
'<p class="item-price-fee clearfix"><span class="sale-price"> $38.5</span> / <span class="blue">0 bids</span></p>'+
'<p class="clearfix"><span class="blue pull-left" style="color: #538dc2;">0 mins left</span></p>'+
'<p><span class="blue">Buy it now ($52.5)</span></p>'+
'<p><span class="pull-right">Portland, TN</span></p>'+
'</div>'+
'</div>'+
'</div>');
}
}
}
var constructRequest = function(){
// Construct the request
url = settings.rootURL;
url += "?OPERATION-NAME="+settings.operationName;
url += "&SERVICE-VERSION="+settings.serviceVersion;
url += "&SECURITY-APPNAME="+settings.securityAppName;
url += "&GLOBAL-ID="+settings.globalID;
url += "&RESPONSE-DATA-FORMAT="+settings.responseFormat;
url += "&callback=_cb_findItemsByKeywords";
url += "&REST-PAYLOAD";
url += "&keywords="+settings.keywords;
url += "&paginationInput.entriesPerPage="+settings.entriesPerPage;
//url += urlfilter;
return url;
}
var submitRequest = function(){
var url = constructRequest();
// Submit the request
s=document.createElement('script'); // create script element
s.src= url;
document.body.appendChild(s);
}
// End _cb_findItemsByKeywords() function
return this.each(function() {
submitRequest();
$(this).append(html);
});
};
})( jQuery );
<html>
<head>
<title>eBay Search Results</title>
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/ebay_jQuery.js"></script>
<script>
$(document).ready(function(){
$('#results').ebay_jQuery();
});
</script>
</head>
<body>
<div id="main-content">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="item-container clearfix" id="item-container" style="position: relative; height: 1204px; ">
<div id="results"></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>