I have a success function in my AJAX which returns the response text from a python script which can be either \"SUCCESS\" or \"EMPTY\". Now I want to place an if-loop insid
This means that what you're responding with isn't "SUCCESS"
. It probably has a line break or other whitespace before or after it, maybe more than one.
Perhaps:
if (/^\s*SUCCESS\s*$/.test(data)) {
// Success
}
Or use jQuery's $.trim
:
if ($.trim(data) === "SUCCESS") {
// Success
}
Also be sure that you're not replying with "Success"
or "success"
, as string comparisons are case-sensitive.
If you're not sure:
if (/^\s*SUCCESS\s*$/i.test(data)) {
// Success
}
or
if ($.trim(data).toUpperCase() === "SUCCESS") {
// Success
}