简体   繁体   中英

Phantomjs script stops execution after json object parsing

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM