gpt4 book ai didi

javascript - '引用错误: httpResponse is not defined' When parsing JSON response of Parse httpRequest

转载 作者:行者123 更新时间:2023-12-03 12:25:07 24 4
gpt4 key购买 nike

我的 promise 语句多次 ping eBay,每次都使用 matchCenterItem 的属性作为参数。当它运行完所有实例后,我希望它将所有响应发送到我的 iOS 应用程序。

我尝试在 response.success 中执行此操作会导致错误,指出 httpResponse is not Defined,即使我事先定义了它。

Parse.Cloud.define("MatchCenterTest", function(request, response) {
//defines which parse class to iterate through
var matchCenterItem = Parse.Object.extend("matchCenterItem");
var query = new Parse.Query(matchCenterItem);
var promises = [];
//setting the limit of items at 10 for now
query.limit(10);
query.find().then(function(results) {
for (i=0; i<results.length; i++) {
url = 'http://svcs.ebay.com/services/search/FindingService/v1';
//push function containing criteria for every matchCenterItem into promises array
promises.push(function() {
return 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',
'REST-PAYLOAD&sortOrder' : 'BestMatch',
'paginationInput.entriesPerPage' : '3',
'outputSelector=AspectHistogram&itemFilter(0).name=Condition&itemFilter(0).value(0)' : results[i].get('itemCondition'),
'itemFilter(1).name=MaxPrice&itemFilter(1).value' : results[i].get('maxPrice'),
'itemFilter(1).paramName=Currency&itemFilter(1).paramValue' : 'USD',
'itemFilter(2).name=MinPrice&itemFilter(2).value' : results[i].get('minPrice'),
'itemFilter(2).paramName=Currency&itemFilter(2).paramValue' : 'USD',
//'itemFilter(3).name=LocatedIn&itemFilter(3).Value' : request.params.itemLocation,
'itemFilter(3).name=ListingType&itemFilter(3).value' : 'FixedPrice',
'keywords' : results[i].get('searchTerm'),
}
});
});
}
Parse.Promise.when(promises).then(function() {
var eBayResults = JSON.parse(httpResponse.text);
for (i=0; i<eBayResults.length; i++)
{
console.log(eBayResults[i]); // So you can see what the response
// looks like for each httpRequest that was made
}
// and by the way if this is the end of your function, then here you can call
response.success(eBayResults);
}, function(err) {
console.log('error!');
response.error();
});
});
});

最佳答案

尝试将此片段更改为

Parse.Promise.when(promises).then(function(httpResponse) {
var eBayResults = JSON.parse(httpResponse.text);
for (i=0; i<eBayResults.length; i++)
{
console.log(eBayResults[i]); // So you can see what the response
// looks like for each httpRequest that was made
}

假设您的 Promise 对象返回 httpResponse。

关于javascript - '引用错误: httpResponse is not defined' When parsing JSON response of Parse httpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24248801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com