Upon receiving a JSON response, it is successfully displayed to users without any issues. However, I am encountering a problem when trying to show a JavaScript alert.
During the initial page load, the 'var' is empty, so I have disabled the JavaScript processing for this scenario. But once the form is submitted and JSON data is returned, the 'var' is no longer empty. The JSON data is correctly formatted and visible as: { x: 3, y: 33.6 },{ x: 4, y: 92.6 },{ x: 5, y: 121.2 }. Despite this, when attempting to trigger an alert using JavaScript, it fails to work - only displaying an empty message instead of the intended result.
<script>
$(document).ready(function() {
var ndhtml =[];
if(ndhtml.length==0)
{
alert('empty string')
}
else
{
var kkpppf=$("#chek").html(ndhtml);
alert('done');
}
});
</script>
I would greatly appreciate any advice on how to update the JSON data here. The first JS file is external, and its code is:
$(document).ready(function() {
(function() {
$('#upload-form2').ajaxForm({
dataType: 'json',
success: function(data) {
var ndhtml = '',
downlo;
for (var i = 0; i < data.length; i++) {
downlo = data[i];
ndhtml += '' + downlo.ndchart + '';
}
$('#chek').html(ndhtml);
}
})
})();
});