2016-07-21 3 views
-2

웹 메서드가 있으며 jQuery를 사용하여 팝업을 표시합니다. 데이터가있을 때 검색 버튼을 클릭하면 정상적으로 작동하지만 아무 데이터도없는 경우 레이블에 "데이터 없음"메시지를 표시하고 데이터가 없을 때 팝업이 나타나서는 안됩니다. 이 코드 시도 :데이터가 없을 때 메시지 표시

업데이트 된 코드를

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'); 
} 
} , 

답변

1

당신이이 부분을 제거 할 수 있습니다 위의 방법을 다음과 같은 경우 당신은 아약스 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 때문에 고유 한 JSON 문자열이있을 수 있다면 당신은 또한

$("#search_data").on('click',function(){ 
    // Rest of the code 
}) 
+0

를 사용할 수 있지만 항목으로, 당신은 할 수 'result'를 변환하고 검사하십시오 : 'jResult = JSON.parse (result); if (result && jResult.length> 0) {...}' – Whothehellisthat

+0

@ user2181397 내가 이것을 시도 할 때 코드에이 쇼가 표시됩니다. 예외는 데이터가 없기 때문에 발생합니다 .. 내가 이것을 원하지 않기 때문에 .. 이것을 확인하십시오 https://media.giphy.com/media/26gJznDimxRyV0zi8/giphy.gif –

+0

이 쇼 오류 : Uncaught TypeError : undefined의 'length'속성을 읽을 수 없습니다. 내가 console @ user2181397을 확인했을 때 –

관련 문제