-1

I have a very simple restful api on flask.

#!flask/bin/python
from flask import Flask, jsonify, Response

app = Flask(__name__)

@app.route('/todo/api/v1.0/notes', methods=['GET'])
def get_tasks():
    return jsonify({'key': 'value'})

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

And I have AngularJS controller like this:

var app = angular.module('notesApp',['angular-markdown-editable']);

app.controller('notesController',function($scope, $http, $window){

    $http({
        method: 'GET',
        url: "http://127.0.0.1:5000/hello"
    }).then(function successCallback(response) {
        $window.alert(":)");

    }, function errorCallback(response) {
        $window.alert(":(");
    });
});

Problem: i do not receive any objects (errorCallback always executes).

When i try:

curl -i http://127.0.0.1:5000/hello

i have result:`

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 5
Server: Werkzeug/0.11.10 Python/2.7.6
Date: Wed, 25 May 2016 03:09:54 GMT

Hello

When my app send request to the server i have:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 319-334-341
 127.0.0.1 - - [25/May/2016 05:58:20] "GET /hello HTTP/1.1" 200 -

When i try to get data from file or remote server all is ok. I have problems only with my local server.

P.S. Sorry for my English :)

antonid
  • 178
  • 1
  • 9
  • What's the error say? Change your error callback to this: function errorCallback(response) { console.log(response); } also, check the network tab in your browser's developer tools (cmd + option + i to open developer tools) – ajHurliman May 25 '16 at 03:24
  • Can you please paste implementation of /hello route ? – Hassan Mehmood May 25 '16 at 03:36
  • Thank you! I had "CORS header 'Access-Control-Allow-Origin' missing" and already had fixed it. – antonid May 25 '16 at 05:28

1 Answers1

0

Solved. I had "CORS header 'Access-Control-Allow-Origin' missing" error. How to solve it.

Community
  • 1
  • 1
antonid
  • 178
  • 1
  • 9