1

In Angularjs Can we send data using $http service with method "JSONP"

     $http({
        method: 'JSONP',
        url: 'http://plv.localhost/register?callback=JSON_CALLBACK',
        data  : { name : 'some name' }
      }).success(function(data, status , header, config){
           console.log('success');
      }).error(function(data, status , header, config){
           console.log('error');
      });
2
  • Yes you can use JSONP. What is the error, etc? You are not giving us much information. Commented Feb 14, 2014 at 12:27
  • @SamV i want to pass data : { name : 'some name' } so on server side (PHP) i can access $_POST['name'] Commented Feb 14, 2014 at 12:29

1 Answer 1

1

Yes, you can! See ng.$http. Your url is missing the callback parameter:

$http({
    method: 'jsonp',
    url: 'http://plv.localhost/register?callback=JSON_CALLBACK',
    params: { name: 'some name' }
}).success(function(data, status , header, config) {
    console.log('success');
}).error(function(data, status , header, config) {
    console.log('error');
});
Sign up to request clarification or add additional context in comments.

4 Comments

still data : { name : 'some name' } is not passing in request body
the problem is angular use GET method for JSONP request so how can we send the post parameters ?
I've updated my answer. Use params instead of data. Remember, JSONP is a simple GET request, so there is no message body.
"You can no longer use the JSON_CALLBACK string as a placeholder for specifying where the callback parameter value should go". Use this instead: $http.jsonp('some/trusted/url', {jsonpCallbackParam: 'callback'})

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.