Reputation: 36367
I'm trying to pass post data to the following phantomjs script (using php/curl):
server.listen(port, function(request, response) {
// Print some information Just for debug
console.log("request method: ", request.method); // request.method POST or GET
if(request.method == 'POST' ){
console.log("POST params should be next: ");
console.log(request.headers);
code = response.statusCode = 200;
response.write(code);
console.log("POST params: ",request.postRaw);
console.log("POST params: ",JSON.stringify(request.postRaw));
var json = request.postRaw;
obj = JSON.parse(json);
console.log(obj.email);
console.log(obj.pass);
var userName = json.stringify(obj.email);
var userPass = json.stringify(obj.pass);
console.log("I'm here");
I am trying to parse out the username and password from the post request. I notice that if I leave in:
var userName = json.stringify(obj.email);
var userPass = json.stringify(obj.pass);
the script will hang after:
console.log("I'm here");
If I remove these 2 lines the entire script will execute normally. Why is this happening? How can I fix this so I can parse the json object (obj), but the script will not hang?
Upvotes: 0
Views: 428
Reputation: 1636
In regular javascript, JSON is capitalized (and case-sensitive). Not sure how PhantomJS' subset of javascript lines up with regular javascript, but it'd be my guess that you should probably use capital-case JSON there too.
So for example:
JSON.stringify(obj.email);
Upvotes: 1