Welcome Guest, Not a member yet? Register   Sign In
How to display a custom error message in Jquery?
#1

[eluser]qpixo[/eluser]
I'm trying to pass user input form data jquery/ajax to check if there's any. Actually I can grab them from server while using json_encode() method PHP side and display the result in Jquery.


How to display a custom error message in Jquery when it can not find anything return in Jquery HTML client side? I'm bit new with Jquery syntax.

Code:
$(document).ready(function() {
$('#keyword').keyup(function(event) {
  event.preventDefault();

  // Get input form
  var keyword = $('#keyword').val();
  var path = "<?php echo site_url('controller/searchSuggestion'); ?>";

  if (keyword.length >= 3) {
   $('#keyword').addClass('loading');
   $.ajax({
    url: path,
    type: "POST",
    data: { search: keyword },
    dataType: "json",
    success: function(data) {
     $('#suggestionResult').fadeIn(500);
     $('#keyword').removeClass('loading');
  
     firstIndex = 0;
     limit = 25;
          
     $.each(data.tabResults, function(i, data) {
      content = "<ul><li class='result'><strong>" + UCFirstChar(data.title) + "</strong></li>";
    
     if (data.actors.length > limit) {
      content += "<li class='result'>" + UCFirstChar(data.actors.substring(firstIndex, limit)) + "...</li>";
     }
     content += "</ul>";
     $(content).appendTo('#suggestionResult');
    });

    error:function (xhr, textStatus, thrownError, data) {
     console.log("Can't find search item...");
                    console.log(">> Update Error Status: ", xhr.status, " Error Thrown: ", thrownError);
    });
   } else {
   $('#suggestionResult').fadeOut(500);
  }
});




Theme © iAndrew 2016 - Forum software by © MyBB