I have no problem with the request and response process, Until I try to parse/process the json data returned from laravel when the error occurs.
I want to display a messsage error when the uploaded file is larger than the system accepts. My action is something like this:
...
if($_FILES['file1']['size'] > 0)
{
http_response_code(413);
return Response()->json(["errorMsg" => "Your file is too large!"], 413);
}
....
Client code:
$.ajax({
type: "POST",
url: "/anuncio/realizar_upload_foto",
contentType: false,
cache: false,
dataType: "JSON",
processData: false
...
...
error: function (xh, jso)
{
alert(jso.errorMsg); //undefined here
}
});
413)