Display message when there is no data


#1

I have webmethod and jquery for display chart in pop up … so when i click on search button when there is data then working fine but when there is no data i want to display message “NO Data” in label … and also pop must not display when there is no data how i do this … check i try this code

<div id="divcontainer" style="display: none" align = "center">
<div id="container" class="cont_charts">

</div>

and for pop up

<script type="text/javascript" >
$(function () {
$("#divcontainer").dialog({
modal: true,
autoOpen: false,
title: "Chart",
width: 600,
height: 450
});
$("#search_data").click(function () {
$("#divcontainer").dialog('open');

});
});

when i try this

success: function (result) {
                debugger;
                var myData = JSON.parse(result.d);
                debugger
                console.log(JSON.parse(result.d));
                debugger;
                if (myData !== null && myData.length == 0) {
                    $("#Label4").text('No data found')
                    return;
                }

                strarr = result.d;
                var myarr = strarr;
                Drewchart(myarr); // here you could pass in myData and drop the JSON.parse in this method
            },

this show not any error but this also not show any message. e.g. No data found


#2

myData is an object (as JSON.parse return an object), so its length is undefined ! The second part of your test is always false. You should try :
if (myData !== null && Object.keys(myData).length == 0) {

For exemple in my console :

> var test={}
← undefined
> test !== null
← true
> test.length == 0
← false // test is not a number, a string or an array
> test.length == undefined
← true
> Object.keys(test).length == 0
← true // YES !


#3

hi … when i try this …

            success: function (result) {
            debugger;
            var myData = JSON.parse(result.d);
            debugger
            console.log(JSON.parse(result.d));
            debugger;
            if (myData !== null && Object.keys(myData).length == 0) {
                $("#<%=Label4.ClientID%>").text('No data found');
                $("#tabledata").hide();
                $("#cont").hide()
                return;
            }

            strarr = result.d;
            var myarr = strarr;
            Drewchart(myarr); // here you could pass in myData and drop the JSON.parse in this method
        },

hi when when i ones select date from date ie.g. 1/02/2016 to 28/02/2016 then data is display and when i select date ie. 1/02/2016-07/02/2016 then no data beacuse there is no data in tables according to these dates so this is work fine but when i again select dates 1/02/2016 to 28/02/2016 then no data is display .


#4

@ratnoz check please