1

With this piece of code I'm trying to get data from server

$scope.get_file_list = function() {
            delete $http.defaults.headers.common['X-Requested-With']; //We don't wat OPTIONS but GET request
            $http({method: 'GET', url: backendUrl + '/session/' + $scope.id + '/list'})
                .success(function(data, status, headers, config) {
                    // ...
                })
                .error(function(data, status, headers, config) { console.log(
                    'error\ndata: '+data+
                    '\nstatus: '+status); });

The server:

from flask import Flask, request
from werkzeug import secure_filename
import glob, os


app = Flask(__name__)

@app.route('/session/<session_id>/list', methods = ['GET'])
def get_file_list(session_id):
        # ...

@app.route('/session/<session_id>/upload', methods = ['POST'])
def upload_file(session_id):
        # ...

if __name__ == '__main__':
        app.run(debug = True, port=80)

And here is the browser's console output

[18:58:37.409] "error
data: 
status: 0

Server responds with code 200 and when I tested it with browser everything was okay(server sent data without any warning in console). Maybe I should do this with jQuery?

André Dion
  • 19,231
  • 7
  • 52
  • 59
xaxes
  • 237
  • 6
  • 21

1 Answers1

0

The status code 0 is probably due to cross domain request(i.e webapp is on foo.com and server is on bar.com) or unreachable server. For more detailed explaination chekout the answer for

ajax status = 0

jQuery Ajax - Status Code 0?

Community
  • 1
  • 1
Deepak N
  • 2,501
  • 2
  • 29
  • 44
  • No, the server's address is 127.0.0.1 and the request reaches the server. – xaxes Sep 18 '13 at 18:59
  • 1
    Can you check the status of the request in network tab of browser(chrome). See if you get "Cancelled" in the status. – Deepak N Sep 18 '13 at 19:03
  • In Chromium console there is "XMLHttpRequest cannot load 127.0.0.1/session/test_session/list. Origin localhost:9000 is not allowed by Access-Control-Allow-Origin.". Firefox didn't show that. By google I figured out that Ajax requests cannot be done to other domain or even other port. I should serve data from the same server that I serve the entire site – xaxes Sep 18 '13 at 20:33
  • You need to access your webapp from 127.0.0.1:9000 instead of localhost:9000. – Deepak N Sep 19 '13 at 04:48