Added failure handling and POST requests to $.ajax