0

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";
    }
 
}
1
  • Welcome to Stack Overflow. It looks like you have your answer now. In the future, though, please be sure to include details on what you mean by "it is not working". For instance, are you getting a JavaScript error in the console? Commented Aug 5, 2021 at 21:15

2 Answers 2

1

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
            }
          });
Sign up to request clarification or add additional context in comments.

Comments

0

There isn't sufficient code to know why is not working. IMHO the ajax call is not handling the error. Try to edit your code as follow:

$.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: function(data) {
      handleResult(data); 
    }
    error: function(data) {
      handleError(data); 
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.