title: Ajax code for live search bar.If no data is found it is not showing error
body: <p>If the return has data then the code works fine. But if it is empty it is supposed to show error log. But not happening</p>
  
  <pre><code>$.ajax({
  type: "POST",
  url: "&lt;?php echo base_url();?&gt;homecontroller/category_search_name",
  data: {search_name: search_text},
  success: function(data){    
          var mainObj = JSON.parse(data);
          var j = 1;
          var k = '&lt;tbody&gt;'
      for(i = 0;i &lt; mainObj.length; i++){
          k+= '&lt;tr&gt;';
           k+= '&lt;td class="column1"&gt;' + j + '&lt;/td&gt;';
          k+= '&lt;td class="column2"&gt;' + mainObj[i].s_name + '&lt;/td&gt;';
          k+= '&lt;td class="column3"&gt;' + mainObj[i].s_admissionno + '&lt;/td&gt;';
          k+= '&lt;td class="column4"&gt;' + mainObj[i].s_dob + '&lt;/td&gt;';
          k+= '&lt;td class="column5"&gt;' + mainObj[i].s_address + '&lt;/td&gt;';
          k+= '&lt;/tr&gt;';
          j++;
          }
      k+='&lt;/tbody&gt;';
      document.getElementById('tbody').innerHTML = k;
                      },
          error:function(jqXHR, textStatus, errorThrown){
                  alert("error");
          }                   
  
                  });
  </code></pre>