javascript - Having trouble defining httpResponse in callback function -



javascript - Having trouble defining httpResponse in callback function -

i'm using promise create httprequest functions every instance of matchcenteritem, force them in array, run them in row. want collect httpresponse of every 1 of these functions, , force them ebaypingresults array. when run this, error stating following:

failed with: typeerror: cannot read property 'text' of undefined @ collectebayresults (main.js:444:57) @ null.<anonymous> (main.js:450:15) @ e (parse.js:2:5101) @ c.extend.then (parse.js:2:5447) @ main.js:439:40 @ e (parse.js:2:5101) @ parse.js:2:4651 @ array.foreach (native) @ object.x.each.x.foreach [as _arrayeach] (parse.js:1:665) @ c.extend.resolve (parse.js:2:4602)

the line it's referring this: var httpresponse = json.parse(httpresponse.text);

here's total code:

parse.cloud.define("matchcentertest", function(request, response) { //defines parse class iterate through var matchcenteritem = parse.object.extend("matchcenteritem"); var query = new parse.query(matchcenteritem); var promises = []; //setting limit of items @ 10 query.limit(10); query.find().then(function(results) { (i=0; i<results.length; i++) { console.log(results[i].get('searchterm')) url = 'http://svcs.ebay.com/services/search/findingservice/v1'; //push function containing criteria every matchcenteritem promises array promises.push(function() { homecoming 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'), } }); }); } console.log(promises); parse.promise.when(promises).then(function(results){ var ebaypingresults = []; function collectebayresults (httpresponse){ var httpresponse = json.parse(httpresponse.text); ebaypingresults.push(httpresponse); } (i=0; i<promises.length; i++) { collectebayresults(httpresponse); } console.log(ebaypingresults); response.success( { "top 3": ebaypingresults } ); }, function(err) { console.log('error!'); response.error('damn man'); }); }); });

i've written previous function referenced httpresponse in way success function, , worked fine, not sure why it's not working in case.

javascript json parse.com httprequest httpresponse

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -