【发布时间】:2019-03-13 01:58:01
【问题描述】:
在我的 Angular 应用程序中使用 Ebay API 时遇到问题。我正在做的是从 Ebay 以 JSON 的形式取回数据。这一切都很好,但我不断收到此错误:
Uncaught ReferenceError: _cb_findItemsByKeywords is not defined
在下面查看我的 TypeScript 代码:
import { Component, OnInit, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { url } from 'inspector';
@Component({
selector: 'app-web-scrape',
templateUrl: './web-scrape.component.html',
styleUrls: ['./web-scrape.component.css']
})
@Injectable({
providedIn: 'root'
})
export class WebScrapeComponent implements OnInit {
_cb_findItemsByKeywords(root) {
var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
var html = [];
html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');
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('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' +
'<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td></tr>');
}
}
html.push('</tbody></table>');
document.getElementById("results").innerHTML = html.join("");
} // End _cb_findItemsByKeywords() function
ngOnInit() {
var url = "https://svcs.ebay.com/services/search/FindingService/v1";
url += "?OPERATION-NAME=findItemsByKeywords";
url += "&SERVICE-VERSION=1.0.0";
url += "&SECURITY-APPNAME=ConorRaf-TheEazyT-PRD-d55b8f6ea-a1f297a5";
url += "&GLOBAL-ID=EBAY-US";
url += "&RESPONSE-DATA-FORMAT=JSON";
url += "&callback=_cb_findItemsByKeywords";
url += "&REST-PAYLOAD";
url += "&keywords=harry%20potter";
url += "&paginationInput.entriesPerPage=3";
console.log("hello from ts");
var s=document.createElement('script'); // create script element
s.src = url;
console.log(s.src)
document.body.appendChild(s);
}
}
代码编译良好,并返回某种 JSON 对象,但我在控制台中收到此错误:
错误似乎在回调中:
HTML仅供参考:
<html>
<head>
<title>eBay Search Results</title>
</head>
<body>
<h1>eBay Search Results</h1>
<div id="results"></div>
</body>
</html>
【问题讨论】:
-
你在哪里调用了_cb_findItemsByKeywords方法?
-
它在字符串“url”中调用。它被附加到字符串中。
标签: angular typescript ebay-api