I've searched around the web and such but so far unsure of how to fix my problem as they seem to delve into other areas and not focused on mine.
So, I'd like to know the best way of retrieving a record or records from a database using jQuery and Ajax, and without using PHP.
I am able to retrieve the whole database with this code
function getRecords(){
var url = 'http://myurl/reports?callback=?';
$.getJSON(url, null, function(data){
$.each(data, function(key, value){
value.date;
value.area;
value.details;
value.number;
})
});
};
(That code is not the full code, just an example of it). And I can access the required data using the above value.var.
I can also send/update/delete records to the database, here's an example of my deletion code
function DeleteRecord(){
$.ajax({
crossDomain: true,
method: 'POST',
url: 'http://url/delete',
data: {"ID": newID},
success: function(cb){
console.log("ID to be deleted is : " + newID);
},
error: function(){
alert('error');
}
});
}
API for the deletion:
restapi.post('/delete', function(req, res){
var delID = req.body.ID;
db.run("DELETE FROM database WHERE Id='"+delID+"'");
});
My problem occurs when I need to send a request which I assume would be a .get request to the server which would pass across the search variable, and then retrieve the records from the database based on the variable
so the sql statement would be something like
("SELECT * FROM database WHERE number='"+variable+"'", function(err, data)
I just can't seem to grasp whether this should be a get request, a post request, a post request with an inserted get request.
I am using sqlite for the database, javascript, jQuery and Ajax.
Any help would be appreciated on where to start with this, as examples I have seen implement PHP and that's not what I am using.