-1

When I want to submit the form data with ajax the error handler is not showing an error. It's just responding this:

{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}abort: ƒ (e)always: ƒ ()arguments: (...)caller: (...)length: 0name: "always"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:2[[Scopes]]: Scopes[3]catch: ƒ (e)done: ƒ ()fail: ƒ ()getAllResponseHeaders: ƒ ()getResponseHeader: ƒ (e)overrideMimeType: ƒ (e)arguments: (...)caller: (...)length: 1name: "overrideMimeType"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:2[[Scopes]]: Scopes[3]pipe: ƒ ()progress: ƒ ()promise: ƒ (e)readyState: 4responseText: "<script>console.log('gefunden');</script>
↵<!DOCTY"setRequestHeader: ƒ (e,t)arguments: (...)caller: (...)length: 2name: "setRequestHeader"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:2[[Scopes]]: Scopes[3]state: ƒ ()status: 200statusCode: ƒ (e)arguments: (...)caller: (...)length: 1name: "statusCode"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:2[[Scopes]]: Scopes[3]statusText: "parsererror"then: ƒ (t,n,r)arguments: (...)caller: (...)length: 3name: "then"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: jquery.min.js:2[[Scopes]]: Scopes[3]__proto__: Object

js/ajax code:

let form = $("#form");

   $("#form").on("submit", function(e) {
       e.preventDefault();
                          
       $.ajax({
         url: "file.php",
         method: "POST",
         dataType: 'json',
         data: {
         test: 1
         },
         success: function (r) {
           console.log("bla");
         },
         error: function(data) {
           console.log(data);
         }
       });
    });
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
DevNewbie
  • 69
  • 5

1 Answers1

1

The first argument to the error: function is the jqXHR object, not the error message. The error message is in the third argument. So it should be:

error: function(jqXHR, textStatus, errorMessage) {
    console.log(errorMessage);
}
Barmar
  • 741,623
  • 53
  • 500
  • 612