0

I'm trying to call my simple web api developed in Jersey, which results in:

[
    {
        "id": 1,
        "name": "Facebook",
        "userName": "abc@gmail.com",
        "password": "Qwerty@123"
    }
]

My jsonp get request looks like this:

this.jsonp.get('http://localhost:8080/api/rest/domains?callback=JSONP_CALLBACK')
            .toPromise()
            .then(response => console.log("Success: " + response),
                err => console.log("Failed: " + err));

However, I'm getting following message printed in console:

Failed: Response with status: 200 Ok for URL: http://localhost:8080/DomainServiceApi/rest/domains?callback=ng_jsonp.__req0.finished

I can't figure out what is wrong with this.

EDIT: Finally my problem got solved. I returned back to using http.get method. Then on removing my now useless in memory web api imports, I got the error message that "Access-Control-Allow-Origin" should be included in my headers in the response on server side. So I included this header in my Jersey web api and everything is working fine.

If anyone is using Jersey, read How to add headers in Jersey response.

Claies
  • 22,124
  • 4
  • 53
  • 77
Rohit Singh
  • 2,143
  • 3
  • 13
  • 16

1 Answers1

1

200 is just the GET response which are coming through server .(Server sent the json) But i guess the json request is not formatted well . Can you please look into the json request if its well formatted . Can you please post you json here . Please let me know if its works .

Manish Kumar
  • 595
  • 2
  • 15
  • I am also guessing that this might be related with the format of my json. I have already posted my json above in the question. Are you asking for something else. * That is the response I'm getting in postman. – Rohit Singh Nov 04 '16 at 06:44
  • I think api you are hitting doesn't support JSONP. Can you please look into this way. – Manish Kumar Nov 04 '16 at 10:49
  • See in console you will find url like this :- – Manish Kumar Nov 04 '16 at 11:27
  • http://localhost:9090/api/rest/domains?callback=angular.callbacks._0, http://localhost:9090/api/rest/domains?callback=angular.callbacks._1 Hit your server , you will get 404 error , so its error and going to print inside error code..May be its a reason . – Manish Kumar Nov 04 '16 at 11:28
  • My api doesn't support Jsonp. Previously I thought it doesn't matter. Recently I came to know that the api should also support Jsonp explicitly. – Rohit Singh Nov 04 '16 at 13:04