Reputation: 688
i make a project like this but in the parse a json file come from instagram api i cant read it my code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>tst</title>
<script src="../jq.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".send").click(function(){
var name = $("#name").val();
var my_url= "https://api.instagram.com/v1/tags/"+name+"?access_token=2307573123.2c01fc8.d2a19d4145c84d59962c0db8d418d2a8";
$("#name").val("");
$.ajax({
type: 'GET',
url: my_url,
dataType: 'jsonp',
function(response){
//how????
}
});
});
});
</script>
</head>
<body>
<p id="p1"></p>
<input type="search" id="name" />
<input type="button" class ="send" value="send" />
</body>
</html>
i want to just read a reson .i can pars it but i cant read it. //where i put how??? is my place to read
Upvotes: 0
Views: 670
Reputation: 4544
The API response contains a data property :
GET : https://api.instagram.com/v1/tags/stackoverflow?access_token=xxx
{"data": {"name": "stackoverflow", "media_count": 10769}, "meta": {"code": 200}}
To access values :
success:function(response){
//how????
alert(response.data.name + ' have ' + response.data.media_count + ' media');
}
Upvotes: 1
Reputation: 2266
You have an error in ajax call, not getting response properly, it should be something like:
$(document).ready(function(){
$(".send").click(function(){
var name = $("#name").val();
var my_url= "https://api.instagram.com/v1/tags/"+name+"?access_token=2307573123.2c01fc8.d2a19d4145c84d59962c0db8d418d2a8";
$("#name").val("");
$.ajax({
type: 'GET',
url: my_url,
dataType: 'jsonp'
}).done(function(response){
//response is our object with data
}
);
});
});
Upvotes: 1