0

I am expecting to receive JSON response from the server after authentication has been successful from the RESTful service.

I am using the code below:

 jQuery.ajax({
                        type: "GET",
                        url: "http://dev.ragld.com/hostinfo/",
                        contentType: "json",
                        beforeSend: function(jqXHR){
                            jqXHR.setRequestHeader("Authorization", "Basic cmsdfsdfG~~~~~Q6cmFnbGQ=");
//some characters have been changed for security reasons.
                        },
                        accept: "application/json",
                        async:false,
                        success: function(response){
                            console.log('success called..');
                        },
                        error: function(errorObj){
                            console.log(errorObj);
                        }
    });

For some reasons it isn't selecting method as GET, When I check NET tab of firebug in FF it shows method as OPTIONS instead of GET. Similarly, it doesn't return JSON data I am expecting.

any one who can help?

EDIT Error from chrome, it doesn't say much though: enter image description here

Ghazanfar Mir
  • 3,493
  • 2
  • 26
  • 42

1 Answers1

0

Does your REST api have COORS? If not, you cannot make AJAX calls to an URL that is not on the same domain as you.

Peeter
  • 9,282
  • 5
  • 36
  • 53
  • Yes I can make request from different server. I have another service running which I can access using getJSON which is without authorization and it works. Only this request with authorization doesn't work. – Ghazanfar Mir Sep 27 '12 at 08:20
  • please check my edit, it doesn't say much. and please note the response header is empty. – Ghazanfar Mir Sep 27 '12 at 11:23
  • Try using the Chrome browser to check what it logs to the console. Judging by the picture, the ajax errors for some reason. The errorObj should have enough info in it to verify the reason. – Peeter Sep 27 '12 at 13:38