'Handling Facebook response [duplicate]
I've got this code to handle Facebook response:
if (response && !response.error_message) {
alert('Posting completed with Post ID:' + response.post_id);
FB.api( '/' + response.post_id, function( response ) {
x$().xhr('<?php echo Yii::app()->createUrl('survey/saveSocialMediaPost', array('answer_id'=>$answer->id, 'social_network'=>1)); ?>', {
method: 'POST',
async: true,
meta: response,
});
console.log( response );
});
} else {
alert('Error while posting.');
}
}
As you can see, after a right post what I want to do is call an ajax to do some actions in my database. The problem here is that I don't know how to handle the response. console.log(response) throws something like that:
Object { created_time: "2016-03-05T01:27:27+0000", message: "Prueba de comentarios.", id: "xxxxxx_xxxxx" }
Exactly what I need to get is message
. id is solved with response.post_id.
Solution 1:[1]
How about this:
console.log(response.message);
It´s a simple JSON object, you should get familiar with JSON - it´s very important in the JavaScript world.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | andyrandy |