I'm trying to set up a function to send an ajax, the function should return my ajax result:
var url = localStorage.getItem("site");
var dataForm = new FormData(this);
$.ajax(
{
type: "POST",
url: url ,
data: dataForm ,
contentType: false,
cache: false,
processData:false,
success: function(result)
{
if(result == null || result.length < 3 || result == "ok" || result == " ")
{
return "ok";
}
else
{
return result;
}
},
error: function(xhr, status, error)
{
return error;
}
});
I've tried the code above, changing the FormData
of line 2 that will be passed by parameter.
The return will certainly be a string, but when I try to get the return I can not:
var return = sendAjax (this). // where this is my form
retorno
is always undefined
.
I have already made sure that ajax has a return on function success
What would be the error?