Checking if form has been submitted via ajax – PHP

As the title says, I wanna check if this ajax method has been submitted or not and show the result in a condition.

Here is the Ajax POST code;

$.ajax({
      url: "addorderInfo.php", // Url to which the request is sent
      type: "POST",             // Type of request to be send, called as method
      data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
      contentType: false,       // The content type used when sending data to the server.
      cache: false,             // To unable request pages to be cached
      processData:false,  
      success: handleResult
        });

And here is the condition I put but it is not working.

function handleResult(data){
        
    if(data == 'error'){
        window.location.href ='404.php';
    }
    else{
        $( "#clearcart" ).click();
        window.location.href = "ordercomplited.php";
    }
 
}

Answer

try this

$.ajax({
            url: "addorderInfo.php", 
            type: "POST",             
            data: new FormData(this), 
            contentType: false,        
            cache: false,            
            processData:false, 
            success: function (data) {
                alert(data)
            },
            error: function (error) {
                 alert(error.responseText) // if your request doesn't work
            }
          });