https call returns "HTTP request failed" with Status Code 0

Jan 15, 2012 at 10:14 PM


I can successfully call an odata feed over http using datajs, but when I put my https service I get an error message "HTTP request failed".

Here is the error object:

I'm using basic authentication header.

? err
    message: "HTTP request failed"
    request: {...}
    response: {...}
? err.response
    requestUri: ""
    statusCode: 0
    statusText: ""
    headers: []
    body: ""

How can I debug what is happening ? Thanks


Jan 16, 2012 at 7:26 PM

Hi tiagonmas,

    Hope you are doing great.  You can always debug what's going on over the network by using Fiddler or the browsers debuggin tools.. For example, IE9 has a very good debugger with a network trace. Chrome has also a solid set of developer tools that will also allow you to trace the requests and their responses.. Firefox has the FireBug debugger wich is very solid too. 

    Based on what you post, it looks to me that you are issuing a cross domain request, and the browser is rejecting it because of the same origin policy (hence the HTTP status 0).  The library has support for cross domain requests using JSONP; however, it is off by default and you have to turn it on.  There are to ways to do it, globally by setting the flag  odata.defaultHttpClient.enableJsonpCallback = true;  or per request by setting the enableJsonpCallback property of the request object to true:{ requestUri: "uri", enableJsonpCallback: true} , function (data) { 
    // success function
function (err) {
    // error function.


Alex Trigo.