javascript - 没有数据时显示消息

标签 javascript jquery error-handling popup

我有一个网络方法,我使用jQuery来显示一个 pop 窗口。当我单击搜索按钮时,如果有数据,则可以正常工作,但是当没有数据时,我想在标签中显示一条消息“NO Data”,并且当没有数据时, pop 窗口也不能显示。我尝试了这段代码:

更新代码

    success: function (result) {

if(result !==null && result.length >0){
strarr = result.d;
var myarr = strarr;
$("#divcontainer").dialog('open');
Drewchart(myarr);
}
else{
$("#<%=Label4.ClientID%>").text('No data found')
$("#tabledata").hide();
$("#divcontainer").dialog('hide');
}
} ,

最佳答案

您可以在ajax success函数中执行整个操作

// Rest of the code
success: function (result) {
          if(result !==null && result.length >0){
                strarr = result.d;
                var myarr = strarr;
                 $("#divcontainer").dialog('open');
                 Drewchart(myarr);
           }
         else{
             $("#someDomElement").text('No data found')
           }
        } 

如果您遵循上述方法,则可以删除此部分
$("#search_data").click(function () {
             $("#divcontainer").dialog('open');
  });

因为打开对话框将由
$('[ID*=search_data]').on('click', function () {

注意:由于id是唯一的,因此您可以使用
$("#search_data").on('click',function(){
  // Rest of the code
})

关于javascript - 没有数据时显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38499020/

相关文章:

javascript - 使用 JS(在 FF-Pentadactyl 中),如何处理媒体播放器等网站内容?

javascript - 在滚动 100% 屏幕高度时调整标题大小 - javascript

python - EfficientDet-Custom数据集-StringToNumberOp无法正确转换字符串

javascript - 如何修复 "This operation is not supported in the environment this application is running on. "location.protocol"..."错误?

javascript - Javascript使用什么函数来修改html?

javascript - Jquery .html 后的 DIV 动画

php - 'Zend_Exception' -> 'Registry is already initialized'

yii - Yii从父 Controller 生成错误

javascript - 简单的 JQuery 示例由于未知原因给我带来了麻烦

javascript - 端口 8888 上的 Socket.io 和端口 80 上的网络服务器 - 无法将两者结合起来