Display message when there is no data

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">


and for pop up

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


when i try this

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

                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

image without data

image with data

I think you should try

if (myData === null || myData.length == 0) {

you should get typeof myData for 1st condition and modify accordingle

If result.d simply is an empty array when there’s no data,

if (!result.d.length) {
    $("#Label4").text('No data found')

should suffice.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.