Reputation: 169
I am trying to start some communication between flask server and html page. I included crossdomain code as explained here http://flask.pocoo.org/snippets/56/ and it still won't work. Here is my python code:
from flask import *
from crossdomain import *
app = Flask(__name__)
@app.route('/')
@crossdomain(origin='*')
def pocetna():
return '1'
if __name__ == '__main__':
app.run(host='0.0.0.0',port=8081,debug=True)
and here is my javascript:
function prebaci(){
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (xmlhttp.responseText==1) document.getElementById("kuca").innerHTML="RADI";
else document.getElementById("kuca").innerHTML="NE RADI";
}
}
xmlhttp.open("GET","127.0.0.1:8081",true);
xmlhttp.send();
}
In google chrome error is:
XMLHttpRequest cannot load %3127.0.0.1:8081. Cross origin requests are only supported for HTTP.
And in Mozzila Firefox:
NS_ERROR_DOM_BAD_URI: Access to restricted URI denied
Upvotes: 0
Views: 1071
Reputation: 1121256
Note the specific error message, it is telling you that you are not connecting to a HTTP server; at least Chrome doesn't think so.
Use:
xmlhttp.open("GET","http://127.0.0.1:8081/",true);
e.g. use a properly qualified URL.
Upvotes: 1