-1

I want to make a cross domain request to JSON file residing in another machine from my machine. I used the below code to make that call

 $http.jsonp('http://10.2.1.1/testdata/samplefile.json?callback=jsonpcallback').success(function (data) {
                    var d = data;
                }).error(function (error) {
                    console.log(error);
                });

But, the code always goes inside error function with error undefined. I have made the file to return json as js object since my return type is json. Is there anything wrong with this format or something is missing? angular version 1.4.9.

//samplefile.json 
    var data = {
        "FileType": 0,
        "CurrentGuid": "9b613045-4e5c-4305-81b2-a95a8d82bc5r",
        "LastPublishedDateTime": "2018-10-29T14:41:49.149615Z",
        "Cultures": {
            "LastPublishedDate": "2018-10-29T14:39:10.443742Z",
            "CurrentGuid": "7f116191-18c1-4204-b8cf-3d2a0d5a2drd",
            "ChangeType": 1
        }   
    };
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Monie corleone
  • 1,618
  • 1
  • 16
  • 37

1 Answers1

0

The $http.jsonp method only works with servers that returns a javascript function which is named by the callback parameter.

By convention, the server providing the JSON data offers the requesting website to name the JSONP function, typically using the name jsonp or callback as the named query parameter field name, in its request to the server, e.g.,

<script type="application/javascript"
        src="http://server.example.com/Users/1234?callback=parseResponse">
</script>

In this example, the received payload would be:

parseResponse({"Name": "Foo", "Id": 1234, "Rank": 7});

For more information, see Wikipedia - JSONP

georgeawg
  • 48,608
  • 13
  • 72
  • 95