Here's the thing. I decided to start learning Html/CSS/JS this summer and now that I already dominate Static webpages I'm trying to get over Dynamic webpages. To learn it, I've decided to make a test website that will search (with some filters) books on a database. Since I don't need the database to be relational, I've decided to install MongoDB on my server and use AJAX to communicate with the server, but after some days reading tutorials and going further searching on google, I don't manage to get enough information to make a code that is able to read from the server.
First of all I added a simple JSON book on the database lets assume its url is something like 100.100.100.100:3000/library and the content is:
[
{
"_id":"book1",
"desc":"blablabladescription",
"cost":"15€"
}
]
and now I want to create a button on the html that calls a function to access the database. My general idea on how to do this is this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>mongoDB AJAX demo</title>
<script type='text/javascript' src='jquery-latest.min.js'></script>
<script type='text/javascript'>
function handler() {
var result;
$.ajax({
url: 'http://100.100.100.100:3000/library,
type: 'get',
dataType: 'jsonp',
jsonp: 'jsonp',
success: function (data) {
console.log('success', data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('error', errorThrown);
}
});
return result;
}
</script>
</head>
<body>
<button type="button" onclick="handler()">click</button>
</body>
</html>
This code is a general idea I have on the structure on requesting from my server, but I know it's incomplete. I think I should make some new XMLHttpRequest(); variable.open("GET","something",true); variable.send() and also to use some callbacks to deal with async.
I hope you can help me with this doubts. I just need an explanation on how to do this or some website that has a deep tutorial, I've been using http://www.w3schools.com/ basically.
Thanks, bertri