Simple jquery ajax response on error
jquery, php
Solution
You're missing a concatenation operator and an ampersand, also I wouldn't use 'string' as a variable name:
var str = 'id='+ id + '&USER=1';
That said, 'string' is not a JS reserved word, but still seems like bad practice (to me at least).
What you are passing in your 'string' variable to $.ajax is a query string, I would suggest reading this for more information:
http://en.wikipedia.org/wiki/Query_string
On your question about error handling, one way is to check the response text for something and act accordingly, e.g.:
$.ajax({
type: "POST",
url: "delete.php",
data: string,
cache: false,
success: function(resp){
if(resp == 'error') { //get PHP to echo the string 'error' if something bad happened
alert('There was an error!');
} else {
commentContainer.slideUp('slow', function() {
$(this).remove();
});
$('#load').fadeOut();
}
}
});
Problem
A couple of questions, first with this var string below, the 1 one works but I need to get the second one working, there is a snytax error because I am not sure how to write it ``` var string = 'id='+ id ; var string = 'id='+ id 'USER=1'; ``` Second; This ajax call below, it post to delete.php to delete a comment, it works but I would like to add in some error handling. Once I add it into the backend, how can I make it show an error in jquery ? ``` $.ajax({ type: "POST", url: "delete.php", data: string, cache: false, success: function(){ commentContainer.slideUp('slow', function() {$(this).remove();}); $('#load').fadeOut(); } ```