I have written a code in bottle in python which gets data from mongodb and when the user request the url http://localhost:8080/index/test
from bottle it will return the json result from mongoDB. it works fine when I point my browser to that url, I can see all the result on the browser.
However when I try to send a request from jQuery ajax I always get error, and the request never succeeds.
Has anyone ever done anything similar who can share their approach with me?
MY general question is, what the best way to get data from MongoDB from client side, when using bottle as the server. I have seen some example in Node.js but I want to use python as the server.
I have used this code.
$.ajax({
type: "POST",
url: "http://localhost:8080/hello/test",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
console.log("success");
},
error: function (response){
console.log("failed");
}
});*/
And I have also tried this :
$.post( "http://localhost:8080/hello/test", d)
.done(function( response ) {
console.log("success");
});
no luck with any of these. I have also tried GET instead of post, but no luck.
This is kind of what I have in python side :
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return {'status':'online', 'something':'blah blah'}
run(host='localhost', port=8080)
Many thanks in advance.