I have an array of tags and I want to test them on Instagram to get media_count. Then I want to send the data I get to my symfony controller. This code is working and I reach the alert in my Success function.
for (var i = 0; i < 1; i++) {
var tagname = tags[i];
var url = "https://api.instagram.com/v1/tags/" + tagname + "?client_id=" + clientID;
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: url,
success: function (res) {
var data = "{'name':'" + res.data.name + "','count':'" + res.data.media_count + "'}";
$.ajax({
type: "POST",
url: controller-url,
data: data,
success: function(response) {
alert(data);
}
});
}
});
}
Then I use the solution in this answer to decode my data in controller, like this:
public function createAction(Request $request) {
$params = array();
$content = $this->get("request")->getContent();
$params = json_decode($content, true); // 2nd param to get as array
...
}
But when I try to send $params to a template, it is empty. Why is that, and what am I doing wrong?