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).

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I used $http.jsonp(...) instead -> stackoverflow.com/questions/31504637/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.