2015-07-19 65 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