I'm trying to send an ajax call from the client to my server with data regarding an inputted parameter. When I attempt this, I am able to only see the data in my servers console, not in the browser.
Here in the client is the ajax call with "Peter_Abelard" setup as a demo title. This call gives me a 200 ok status but the response text is empty.
$.ajax({
type: "GET",
url: 'http://localhost:3000/api/wiki/Peter_Abelard',
async: false,
datatype: 'json',
success: function(response){
console.log(response);
}
});
In the server code I have
function getData(name){
wikipedia.page.data(name, { content: true }, function(response) {
console.log(JSON.stringify(response));
var dad = JSON.stringify(response);
fs.writeFile("wikip.txt", dad, function(err) {
if (err) throw err;
console.log('It\'s saved!');
});
return dad;
});
}
app.get('/api/wiki/:que', function(req, res) {
var queryd = req.params.que;
getData(queryd);
res.send(getData(queryd));
});
I believe this problem has something to with the line res.send(getData(queryd))
but I'm not sure what to try. If I am correct, this line should send the proper text to the client.