2015-07-19 66 views
1

如何使用jsonp請求在數據庫中存儲數據?jsonp和post action在離子框架(angular.js)

我管理服務器/客戶端和....我已經嘗試添加回調函數作爲服務器響應之前的字符串和jsonp請求中的參數,但沒有成功。在我的源看一看(離子溶液):http://codepen.io/studentttt/pen/BNPPoP

var d = [{"user_type_id":0, "user_venue_id":0, "fname":r}]; 

    var req = { 
     type : 'POST', //'GET' 
     crossdomain: true, 
     //callback: 'angular.callbacks._0', 
     data: d, 
     contentType: "application/json", 
     dataType: "jsonp", 
     url : 'http://www.where2play.pl/index.php/json/adduser', 
}; 
$http(req).success(function(res){.... 

當我使用GET(方法而不是POST)有相同的錯誤:

"NetworkError: 500 Internal Server Error - http://www.where2play.pl/index.php/json/adduser" 

的adduser 錯誤 app.js(第58行) 詳細錯誤:跨源請求被阻止:同源策略不允許讀取遠程資源http://www.where2play.pl/index.php/json/adduser。 (原因:缺少CORS頭'Access-Control-Allow-Origin')。

回答

0

JSONP只能被用來獲得一個JSON文件,它可以作爲一個

<script src="..."></script> 

當你這樣做,你不能發佈。

在請求中不能同時使用JSONP和POST。

對此事的詳細信息參考:Post data to JsonP

+0

我用$ http.jsonp(...),而不是 - > http://stackoverflow.com/questions/31504637/angular-http-jsonp-method-工程一次只, – studentttt