響應成功(alert-> done),但第二個和另一個命中將響應'錯誤'。
我試着用'cache:false'添加一些配置參數,但仍然只能第一次使用。我應該清除一些緩存/歷史或某事?
$scope.add2 = function() {
var config = {
//url : 'http://www.where2play.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.where2play.pl/index.php/json/adduserget?callback=JSON_CALLBACK&'+ e, config)
$http.jsonp('http://www.where2play.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');
});
};
這是jsonp and post action in ionic framework (angular.js)
新的問題,我已經添加到服務器響應「angular.callbacks._0(」前JSON數據......也許這裏的錯誤?
這是解決方案對於我的問題: 現在我dynamiccaly獲取回調參數,可以通過GET方法在服務器上變化(不總是angular.callback_0,但可以是:angular.callback_1,angular.callback_2等),並將其放在響應數據fe在PHP:
<?php header('content-type: application/json;');
$json=json_encode($result);
echo $_GET['callback'].'('.$json.')';
?>
從那裏你打它,你可以提供的代碼? –
我正在使用離子frm,這裏是sinppets:http://codepen.io/studentttt/pen/BNPPoP – studentttt