I have a script which uses a jQuery AJAX call to return a number between 0-5 and simply changes the value of a textbox with the result. When the script returns 1-5 this works fine and prints the result in the textbox accordingly.
However, on the occasions the script returns 0, nothing gets printed. I'm guessing this is a default behaviour for treating 0 but the problem is 0 is a valid response for the script I am writing and I need it to actually print '0' in the textbox.
I can post my code if necessary but it's a standard basic jQuery AJAX call to a PHP script which echoes the result (0-5) and then the value of a textbox is updated using the AJAX response.
Edit: Code is below as requested
function fetchEWSSScore(input,category) {
$.ajax({
type: "POST",
url: "EWSSTriggerLevel.php",
data: "input=" + input + "&category=" + category,
async: true,
success: function(msg){
EWSS_Score = msg;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
EWSS_Score = 'Invalid';
alert(" Status: " + textStatus + "\n Error message: "+ errorThrown);
}
});
if (isNaN(EWSS_Score)) {
EWSS_Score = 'Invalid';
alert("An invalid response was given while attempting to fetch EWSS Score.");
return false;
} else {
return EWSS_Score;
}
}
function calculateEWSSWeightedScore(input,category,weighted) {
var EWSSScore = fetchEWSSScore(input,category);
$(weighted).val(EWSSScore);
}
$('#heartRate').change(function() {
var category = "HR";
var input = $(this).val();
calculateEWSSWeightedScore(input,category,'#heartRateWeighted');
});
Edit 2: Thanks to @FelixKling for pointing out a bug in my script I didn't even notice existed. However I still have the issue with 0 not being printed.