Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取响应以在Javascript中进一步使用它_Javascript_Facebook_Facebook Graph Api - Fatal编程技术网

获取响应以在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({

如何获得响应以在Javascript中进一步使用它?
请帮助任何人。

你已经走到一半了。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
  }
});