Upon the first response being successful (alert->done), any subsequent hits will result in an 'error' response.
I attempted to resolve this issue by adding some config parameters with 'cache: false', but it still only works the first time. Should I clear some cache/history or something else?
$scope.add2 = function() {
var config = {
//url : 'http://www.***.pl/index.php/json/getallusers',
cache: false,
//type : 'POST',
crossdomain: true,
//callback: 'JSON_CALLBACK',
//data: d,
contentType: "application/json",
dataType: "jsonp",
};
var r = Math.floor(Math.random() * 1000) + 4;
var d = {user_type_id:0, user_venue_id:0, fname:r};
var e = objToString(d);
//$http.jsonp('http://www.***.pl/index.php/json/adduserget?callback=JSON_CALLBACK&'+ e, config)
$http.jsonp('http://www.***.pl/index.php/json/adduserget?callback=JSON_CALLBACK&'+ e)
.success(function(res){
console.log('res:' + res.user);
alert('done');
})
.error(function(){
console.log('error');
alert('error');
});
};
This question can also be found on Stack Overflow regarding jsonp and post action in Ionic framework (angular.js)
I have noticed that the server response now includes 'angular.callbacks._0(' before the JSON data... could this be where the mistake lies?
A potential solution for my issue is as follows: I am dynamically retrieving the callback parameter which may vary (not limited to angular.callback_0, but could be: angular.callback_1, angular.callback_2, etc.) from the GET method on the server and inserting it before the response data using PHP:
<?php header('content-type: application/json;');
$json=json_encode($result);
echo $_GET['callback'].'('.$json.')';
?>