获取响应以在Javascript中进一步使用它
如何获得响应以在Javascript中进一步使用它?获取响应以在Javascript中进一步使用它,javascript,facebook,facebook-graph-api,Javascript,Facebook,Facebook Graph Api,如何获得响应以在Javascript中进一步使用它? 请帮助任何人。你已经走到一半了。jQuery.ajax方法的文档解释说,success选项定义了一个在请求成功时要执行的函数,它将接收响应作为第一个参数 jQuery.ajax({ url:'https://graph.facebook.com/me/feed?message=Hello&method=POST', dataType:'script', success:function(){ jQuery.ajax({
请帮助任何人。你已经走到一半了。jQuery.ajax方法的文档解释说,
success
选项定义了一个在请求成功时要执行的函数,它将接收响应作为第一个参数
jQuery.ajax({
url:'https://graph.facebook.com/me/feed?message=Hello&method=POST',
dataType:'script',
success:function(){
jQuery.ajax({
url:'https://graph.facebook.com/me/feed?message=Hello&method=POST',
dataType:'script',
success:function(response) {
// use repsonse here. For example:
alert(response);
}
});
您的数据类型:'script'
设置可能会遇到一些问题。这告诉jQuery尝试并执行响应数据,就好像它是有效的Javascript一样。也许这就是你想要的,但我觉得你只是想使用数据
就我个人而言,我觉得总是显式声明数据类型是一种很好的做法
jQuery.ajax({
type: 'POST',
url:'https://graph.facebook.com/me/feed?message=Hello&method=POST',
success:function(response) {
// This will display the actual response in your console (e.g. FireBug)
// Note that jQuery may attempt to format the response into an object (if it receives JSON or XML for instance)
console.log(response);
// Do stuff with the response
}
});