Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

Using the $http service (JSONP method) in AngularJS, I am trying to make a call to a hosted web api via a url and also pass data with the request in json format but I'm getting a "Uncaught SyntaxError: Unexpected token :" in my web browser console. Investigating further, I discovered that my WebAPI request returned "{"header":{"status":"ERROR","code":"101"}}". I have no idea why I'm getting this response from the WebAPI from AngularJS as a PHP implementation of same works seamlessly. Below is the code for my controller in Angular JS and the functional PHP version. I would appreciate any hints to make my AngularJS call functional.

Angular


    .controller('RegStateController', ['$scope', '$http', function($scope, $http){
        $product_key = "29E568836TRED8E7315";
        $product_id = "7344";
        $hash = '25b7885uthy80a1623445rtyherww6813b87yht2regh06e6a0abgsnmdjgfa3d9f';

        var arr = [];
        arr.push({"product_key": $product_key});
        arr.push({"product_id": $product_id});
        var xml_data = JSON.stringify(arr);

        $URL = "http://skrinad.me/api/"+$hash+"/json/list/state";

       $http({
         method: 'JSONP',
         url:$URL+"?callback=JSON_CALLBACK",
         params: {
           data: xml_data,
           format:'jsonp'
           //callback: 'JSON_CALLBACK'
          }
       })
       .then(function (response) {
            $scope.data = response.data;
            console.log(response.data)
        });

    }])

PHP


        $product_key = "29E568836TRED8E7315";
        $product_id = 7344;
        $hash = "25b7885uthy80a1623445rtyherww6813b87yht2regh06e6a0abgsnmdjgfa3d9f";

        //JSON Example
        $array['product_key'] = $product_key;
        $array['product_id'] = $product_id;
        $xml_data = json_encode($array);

        $URL = "http://skrinad.me/api/".$hash."/xml/list/state";

        $ch = curl_init($URL);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $output = curl_exec($ch);
        curl_close($ch);

        echo $output;

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.