【发布时间】:2017-05-11 12:54:14
【问题描述】:
我正在尝试从 Instagram api 提供访问令牌,我在 laravel 中使用 ajax 发送我的数据,并在 json 中提供 access_token。 我对显示 ajax jquery 的看法是:
var $data;
$(document).ready(function(){
$("button").click(function(){
$.ajax({
method: 'POST',
url:'https://api.instagram.com/oauth/access_token',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: {client_id: "d52c34",client_secret:"<MY client_secret HERE>",
grant_type:"authorization_code", redirect_uri:"http://ie-asemi.ir/laravel/public/instagram/test",
dataType:"json",
processData: true,
code:"{{$code}}"},
dataType:"json",
contentType: 'application/x-www-form-urlencoded'
});
});
</script>
如何在这个页面获取json结果?enter image description here
我添加了 done 函数,一切都改变了,enter image description here
【问题讨论】:
-
您使用
.done()来返回数据响应。如果是 JSON,则可以轻松访问。 See the examples in the docs here. -
复制和粘贴包含
client_secret的代码时要小心 -
@samiles 我是 jquery 新手,你能帮我更多吗?
-
@ThrowingSpoon 好的,谢谢