获得响应,以便在Javascript中进一步使用它

时间:2013-05-30 12:29:31

标签: javascript facebook facebook-graph-api

 jQuery.ajax({
 url:'https://graph.facebook.com/me/feed?message=Hello&method=POST',
 dataType:'script',
 success:function(){

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

你已经在中途了。 jQuery.ajax方法的文档解释了success选项定义了在请求成功时要执行的函数,并且它将接收响应作为其第一个参数。

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

您的dataType: 'script'设置可能会遇到问题。这告诉jQuery尝试执行响应数据,就像它是有效的Javascript一样。也许那就是你想要的,但听起来像你只是想使用这些数据。

就个人而言,我认为总是明确声明dataType是一种好习惯。