I am trying to make a request from jQuery to see if there is enough resources in the storage to build a house. I do not really understand the difference between the ajax-functions $.get, $.post and $.ajax, and when to use which. I think that $.ajax is a more advanced function which also includes get and post, but when do I use get, and when do I use post? And also, do I use .get in the right way here?
Here is my jQuery code:
var x = 10 // x-position
var y = 10 // y-position
$.get('request.php?house=cottage&x='+x+'&y='+y, function(data){
if(data == 1){ // If there is enough resources etc... return 1.
itemId++; // Set unique id for this building.
$('body').append("<div class='house' id='" + itemId + "'></div>");
$('#'+itemId).css({
marginLeft: x - ($('.house').width())/2,
marginTop: y - ($('.house').width())/2
});
$('#rightMouseMenu').hide();
}
});
And the request.php:
<?php
$house = $_GET['house'];
$x = $_GET['x'];
$x = $_GET['y'];
// Some request to database to see if there is enough resources to build a house in enoughResources()
if(enoughResources() == 1){
echo 1;
}else{
echo 0;
}
?>