I am a noob to jquery and I am stuck on this ajax request. I have a server on my local network running python service. When I hit the server through the browser with the request
http://192.168.0.109:5000/api/environment?seconds=10
I get the JSON I expect shown in the browser. So I know the server is working ok and responding to request OK
{
"Bedroom Light": {
"host": "192.168.0.121",
"model": "Belkin Plugin Socket 1.0",
"name": "Bedroom Light",
"serialnumber": "221323K1300027",
"state": 0,
"type": "LightSwitch"
}
However, when trying to do this through Jquery - I get a jQuery - SyntaxError: Unexpected token : error in the browser console. Here is my Jquery
$(function () {
$.ajax({
url: 'http://192.168.0.109:5000/api/environment?seconds=10',
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
success: function(data) {
console.log('sucess',data);
}
});
});
and I am just running it through the following page through the main.js
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>Home - Dashboard</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
</body>
</html>
I have tried
dataType: 'json',
instead of jsonp and still get this issue. I added the crossdomain: true following another post on this site, but still receive the error.
where am I going wrong here?
my server logs the following in the console when I run the ajax
192.168.0.149 - - [2017-01-07 10:25:53] "GET /api/environment?seconds=10&callback=jQuery11110725321438557059_1483745153757&_=1483745153758 HTTP/1.1" 200 3977 0.510238
it logs this when I hit it through the browser directly.
192.168.0.149 - - [2017-01-07 10:27:02] "GET /api/environment?seconds=10 HTTP/1.1" 200 3977 0.629556
both my webserver and the server running the python service are located on the same network/subnet.
btw: the python services is the http://ouimeaux.readthedocs.io/en/latest/readme.html
thanks in advance