\n\n","text":"The code below enables to detect the facial features. I'm having an issue with getting the response when the request is sent. Please help troubleshoot such issue. \n\n\n\n\n\nFacerect\n\n\n\n\n\n\n","author":{"@type":"Person","name":"lyden"},"dateCreated":"2014-07-03","answerCount":1,"suggestedAnswer":{"@type":"Answer","text":["Hi there!\nSeems like you are trying to perform a cross-domain HTTP request which is blocked by most browsers. Please see the following StackOverflow question: \nhttp://stackoverflow.com/questions/1941340/empty-responsetext-from-xmlhttprequest\n\nA possible solution would be to perform server-side calls to the API instead of using JS and XMLHttpRequest. Hope that helps!\n\nBest regards,\nAndy"],"dateCreated":"2014-07-03","url":"https://rapidapi.com/apicloud/api/facerect/discussions/928/getting-response-issue","upvoteCount":0,"author":{"@type":"Person","name":"apicloud"}}}}

FaceRect

FREE
By apicloud
Updated a month ago
Media
9.2/10
Popularity Score
2260ms
Latency
97%
Success Rate
lyden5 years ago
getting response issueThe code below enables to detect the facial features. I'm having an issue with getting the response when the request is sent. Please help troubleshoot such issue. <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Facerect</title> </head> <body> <script> //chnage this url var image_location="http://apicloud.me/assets/facerect/image4.jpg"; var url ="https://apicloud-facerect.p.mashape.com/process-file.json?"; url += "url=" + encodeURI(image_location); url += "&features=true"; alert(url); var xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET",url,true); xmlhttp.setRequestHeader("X-Mashape-Authorization", "zVNNYMfznlE1LpqFTWDjx7Ddt3yD51oy"); xmlhttp.onreadystatechange=function(){ alert(xmlhttp.readyState + "," + xmlhttp.status); alert(xmlhttp.statusText); alert(xmlhttp.responseText); if(xmlhttp.readyState==4) { alert ("response text = " + xmlhttp.responseText); var response=JSON.parse(xmlhttp.responseText); //alert (xmlhttp.responseText); alert (response.faces[0].features.nose.x); //var response=JSON.parse(xmlhttp.responseText); //alert (xmlhttp.responseText); alert (response.faces[0].features.nose.y); //var response=JSON.parse(xmlhttp.responseText); //alert (xmlhttp.responseText); alert (response.faces[0].features.mouth.x); //var response=JSON.parse(xmlhttp.responseText); //alert (xmlhttp.responseText); alert (response.faces[0].features.mouth.y); alert (response.faces[0].features.eyes[0].x); alert (response.faces[0].features.eyes[0].y); alert (response.faces[0].features.eyes[1].x); alert (response.faces[0].features.eyes[1].y); var x1 = response.faces[0].features.eyes[0].x; var y1 = response.faces[0].features.eyes[0].y; var x2 = response.faces[0].features.eyes[1].x; var y2 = response.faces[0].features.eyes[1].y; var dist = Math.sqrt(((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2))); alert(dist); } } xmlhttp.send(null); </script> </body> </html>
apicloud5 years ago
Hi there! Seems like you are trying to perform a cross-domain HTTP request which is blocked by most browsers. Please see the following StackOverflow question: http://stackoverflow.com/questions/1941340/empty-responsetext-from-xmlhttprequest A possible solution would be to perform server-side calls to the API instead of using JS and XMLHttpRequest. Hope that helps! Best regards, Andy
Hi Developer, feel free to post your answer:

Install SDK for NodeJS

Installing

To utilize unirest for node.js install the the npm module:

$ npm install unirest

After installing the npm package you can now start simplifying requests like so:

var unirest = require('unirest');

Creating Request

unirest.post("https://apicloud-facerect.p.rapidapi.com/process-file.json")
.header("X-RapidAPI-Host", "apicloud-facerect.p.rapidapi.com")
.header("X-RapidAPI-Key", "SIGN-UP-FOR-KEY")
.header("Content-Type", "application/x-www-form-urlencoded")
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});
OAuth2 Authentication
Client ID
Client Secret
OAuth2 Authentication