1

how to use jsonp request to store data in database?

I manage server/client sides and.... I've tried add callback function as a string before server response and as a parameter in jsonp request but without success. Take a look at my source (ionic solution): 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.***.pl/index.php/json/adduser', 
};  
$http(req).success(function(res){....

When I use GET (method instead of POST) there is the same error:

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

adduser error app.js (line 58) detailed error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.***.pl/index.php/json/adduser. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

studentttt
  • 61
  • 9

1 Answers1

1

JSONP can only be used to GET a JSON file, it works as a

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

When you do that, you can't POST.

It is not possible to use JSONP and POST at the same time in a request.

Reference for more info on the matter: Post data to JsonP

Community
  • 1
  • 1
jperelli
  • 6,988
  • 5
  • 50
  • 85
  • I used $http.jsonp(...) instead -> http://stackoverflow.com/questions/31504637/angular-http-jsonp-method-works-only-once – studentttt Jul 19 '15 at 18:42