Hello all, I am trying to create a JavaScript SDK search. I am getting the data I want thru the row and field like so:
Async.chain([
function(done) {
service.login(done);
},
// Perform the search
function(success, done) {
if (!success) {
done("Error logging in");
}
service.search("search XXXXXX | spath YYYYYYY | head 10", {}, done);
},
// Wait until the job is done
function(job, done) {
Async.whilst(
// Loop until it is done
function() { return !job.properties().isDone; },
// Refresh the job on every iteration, but sleep for 1 second
function(iterationDone) {
Async.sleep(1000, function() {
// Refresh the job and note how many events we've looked at so far
job.fetch(function(err) {
iterationDone();
});
});
},
// When we're done, just pass the job forward
function(err) {
done(err, job);
}
);
},
// Print out the statistics and get the results
function(job, done) {
// Ask the server for the results
job.results({}, done);
},
// Print the raw results out
function(results, job, done) {
// Find the index of the fields we want
var rawIndex = utils.indexOf(results.fields, "YYYYYYY");
// Print out each result and the key-value pairs we want
document.write('{"RESULTS":"10", "ZIPS":[');
for(var i = 0; i < results.rows.length; i++) {
if(i>0) document.write(",");
//console.log(results.rows[i][rawIndex]);
document.write('"'+ results.rows[i][rawIndex] + '"' );
if (i== 9) document.write(']}');
}
// Once we're done, cancel the job.
job.cancel(done);
}
],
function(err) {;
}
);
What I want to do is to grab the YYYYY that I am document.write to the page and use it as a JSON file for another page. The problem I am having is I want to import the YYYYY data as a JSON file on my other webpage but I do not know how to write that info into a JSON file. Any help?