So I'm trying to use this web framework Tangelo. In my javascript I use AJAX and I'm trying to get the result of some Python script using AJAX. The python queries a mongodb, but I don't know if the path I specify is correct in AJAX or if I'm missing something. Can someone provide some help, or a better method for doing this.
$.ajax({
url: "service/findRecords/" + database + "/mydb/questions",
data: {search_keyword : srch_kwrd},
dataType: "script",
type: "GET",
sucess: function(rtn){
console.log("I GOT TO THE FUNCTION IN AJAX");
results = rtn;
d3.select("#myapp-content")
.html(results);
d3.select("#myapp-content")
.html(rtn);
},
complete: function(){console.log("Finish ajax");
console.log("Show me potato salad: "+"service/findRecords/" + database + "/mydb/questions");}
});
Sorry didn't explain. The database variable I set to both the string 'mongo' and 'localhost:8080', but that didn't do anything. In my return statement I just want to return the results of the python script. Which is in the service directory as seen above. Its written like this:
import datetime
import itertools
import pymongo
import tangelo
from pymongo import MongoClient
client = MongoClient('localhost',27017)
mydb = client.mydb
question_collection = mydb.questions
search_results = []
#return a list of json objects which represent rows of a database
#i.e. [{1:2},{3:4}]
def run(host, database, collection, search_keyword = None):
If you want to use AJAX to talk to MongoDB, you need to go through the MongoDB's REST API, as documented here
The URL should look something like http://localhost:28017
. From your code, it appears your url looks something like service/findRecords/localhost:8080/mydb/questions
, which is of the wrong shape, and referring to the wrong port.
To debug why the requests from AJAX are failing, you could try using Fiddler.