An if conditional can be used to validate the result of a variable?, something like:
$("#update").submit(function(e){
e.preventDefault();
$.ajax({
url: "ruta/al/archivo/uploadFac.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data){
if(var != 0){
$('#upload').modal('hide');
$('#Fac').modal('hide');
}else{
alert("ERROR");
}
},
error: function(data){
console.log(data)
}
});
});
});
Where the variable "var" is a variable that I get from the uploadFac.php script with which the request was made, can that be done?
Of course you can, but it depends on what type of value you are going to return from the back to the front, if you are going to send an object
json
it would be like this:But if, on the other hand, you are going to send a
string
numeric value, it would be simply with the parameterdata
that receives thesuccess
:Remember that the parameter of the method
success
is the one who receives the data returned by the back.The AJAX structure is an object, this gives us a lot of flexibility to do and undo. What I mean is that, the node
success
stores an anonymous function, and it behaves like any other, you can put any type of code inside.IF, WHILE, FOR
, Even call another AJAX (For this it would be better to use and/or the Jquerypromises
method ).when
I leave you another way of how you can build your AJAX