has no method ' success'"错误-6ren"> has no method ' success'"错误-我正在尝试设置协议(protocol)来处理我的 javascript 函数中的成功和错误,但是当函数成功时它似乎并不合作。我收到以下错误: Failed with: TypeError: Objec-6ren">
gpt4 book ai didi

javascript - response.success 给我 "Object # has no method ' success'"错误
转载 作者:行者123 更新时间:2023-11-28 12:29:57 29 4
gpt4 key购买 nike

我正在尝试设置协议(protocol)来处理我的 javascript 函数中的成功和错误,但是当函数成功时它似乎并不合作。我收到以下错误:

Failed with: TypeError: Object #<Object> has no method 'success'
at Object.Parse.Cloud.httpRequest.success (main.js:77:20)
at Object.<anonymous> (<anonymous>:571:19)

完整功能如下:

// Sends search query to eBay

Parse.Cloud.define("eBayCategorySearch", function(request, response) {
url = 'http://svcs.ebay.com/services/search/FindingService/v1';

Parse.Cloud.httpRequest({
url: url,
params: {
'OPERATION-NAME' : 'findItemsByKeywords',
'SERVICE-VERSION' : '1.12.0',
'SECURITY-APPNAME' : '*App ID GOES HERE*',
'GLOBAL-ID' : 'EBAY-US',
'RESPONSE-DATA-FORMAT' : 'JSON',
'itemFilter(0).name=ListingType' : 'itemFilter(0).value=FixedPrice',
'keywords' : request.params.item,

},
success: function (httpResponse) {


// parses results

var response = JSON.parse(httpResponse.text);
var items = [];

response.findItemsByKeywordsResponse.forEach(function(itemByKeywordsResponse) {
itemByKeywordsResponse.searchResult.forEach(function(result) {
result.item.forEach(function(item) {
items.push(item);
});
});
});


// count number of times each unique primaryCategory shows up (based on categoryId), return top two


var categoryResults = {};

items.forEach(function(item) {
var id = item.primaryCategory[0].categoryId;
if (categoryResults[id]) categoryResults[id]++;
else categoryResults[id] = 1;
});

var top2 = Object.keys(categoryResults).sort(function(a, b)
{return categoryResults[b]-categoryResults[a]; }).slice(0, 2);
console.log('Top categories: ' + top2.join(', '));



// compare categoryResults to userCategory object

var userCategory = ['9355'];

var AnyItemsOfCategoryResultsInUserCategory = Object.keys(categoryResults).some(function(item) {
return userCategory.indexOf(item) > -1;
});
console.log('Matches found: ' + AnyItemsOfCategoryResultsInUserCategory);

var ItemsOfCategoryResultsInUserCategory = Object.keys(categoryResults).filter(function(item) {
return userCategory.indexOf(item) > -1;
});
console.log('User categories that match search: ' + ItemsOfCategoryResultsInUserCategory);

response.success('Victory!');


},
error: function (httpResponse) {
console.log('error!!!');
response.error('Request failed with response code ' + httpResponse.status);
}
});
});

它引用的第77行是这个:

response.success('Victory!');

最佳答案

行:

var response = JSON.parse(httpResponse.text);

您将 response 设置为 json 对象,据我所知,没有 response.success 函数添加到该对象中。我猜您想要的响应就是传递给

的响应
Parse.Cloud.define("eBayCategorySearch", function(request, response) {

因此您需要重命名其中一个响应对象。

关于javascript - response.success 给我 "Object #<Object> has no method ' success'"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23071508/

29 4 0