0

I'm trying to receive data in AngularJs via JSONP using the $http.jsonp(url). I'm new to AngularJs and Javascript in general. What am I doing wrong?

This is the code I used:

angular.module('tutorialApp', []).controller('ContentCtrl', function($scope, $http){

    var url = "/somejsonp.jsonp?callback=JSON_CALLBACK";

    $http.jsonp(url)
        .success(function(data){
            console.log(data);
        });
});

I keep getting:

Uncaught ReferenceError: jsonCallback is not defined

My jsonp looks like this:

jsonCallback([
    {
        "from": "Lissabon (LIS)",
        "to": "Bangkok (BKK)",
    },
    {
        "from": "Hamburg (HAM)",
        "to": "Vienna (VIE)",
    }
]);
Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
Aoke
  • 43
  • 1
  • 6
  • little confused, you passed `JSON_CALLBACK` and response wrapped in `jsonCallback`, Ideally it should have wrapped inside `JSON_CALLBACK` only.. are you sure you are getting a response what you have pasted over here? – Pankaj Parkar Aug 12 '16 at 15:00
  • Check the server configuration, looks like it somehow attempts to translate the passed callback param into a 'proper' form - which shouldn't be done. The Angular part seems to be correct here. – raina77ow Aug 12 '16 at 15:02
  • I learned here [link](http://stackoverflow.com/questions/12066002/parsing-jsonp-http-jsonp-response-in-angular-js) to use callback=?JSON_CALLBACK. But I keep getting "jsonCallback is not defined" (all?callback=angular.callbacks._0:1 Uncaught ReferenceError: jsonCallback is not defined) – Aoke Aug 12 '16 at 15:18
  • What's the server, do you control it? If you provide another name (like `SONJ_CALLBACK`), what'll be the resulting response? – raina77ow Aug 12 '16 at 15:25
  • You guys are right. I think it might be connected to the htaccess in someone way. I will have a look into it. Thank you very much so far. – Aoke Aug 12 '16 at 19:05

0 Answers0