This is a question where my overall approach might be wrong, but I hope you can help out.
I have a function, where I want to make a call to my server. I call that function cleanString
. That cleanString
function calls the server, using an AJAX call.
I know that AJAX is async, so I set the async: false
value of my AJAX call.
But right now, I get undefined
from the cleanString
method, no matter what I do. As you can see in the method, I even return a hardcoded string just to test it.
My code calling the function:
var serverName = cleanString(file.name);
fileList[file.name] = { "serverFileName": serverName, "fileName": file.name };
console.log(fileList);
This is the cleanString function:
function cleanString(str) {
$.ajax({
url: '/SingleLetter/StripString',
type: 'POST',
async: false,
data: {
'str': str
},
dataType: 'json',
success: function (data) {
return 'abekat2';
}
});
}
So basically: how do I make sure that the variable serverName
get's the value "abekat2", from the cleanString
method?