Simple jQuery ajax error response

A few questions, first with this var line below, 1 works, but I need the second to work, there is a snytax error, because I'm not sure how to write it

var string = 'id='+ id ;
var string = 'id='+ id 'USER=1';

Secondly; This ajax call is below, it sends delete.php to delete the comment, it works, but I would like to add some error handling. Once I add it to 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();
  }
+3
source share
2 answers

You are missing the concatenation operator and ampersand, and I would not use "string" as the variable name:

var str = 'id='+ id + '&USER=1';

, "" JS, - ( ).

, 'string' $.ajax, , :

http://en.wikipedia.org/wiki/Query_string

- - , :

$.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();   
    }
   }
  });
+9

HTTP ?

HTTP-, "", "",

docs

0

Source: https://habr.com/ru/post/1714822/


All Articles