jquery - How to Diplay "No result Found " in Autocomplete using $.getJSON -


i want show "no result found " message when response empty.in case when end session expired @ time return login page need json data how can handle html data .

    $( "#customers_name" )   .bind( "keydown", function( event ) {     if ( event.keycode === $.ui.keycode.tab &&         $( ).autocomplete( "instance" ).menu.active ) {       event.preventdefault();     }   })   .autocomplete({     source: function( request, response ) {       $.getjson( "ajax_functions.php", {         term: extractlast( request.term ),         console: $('select[name="console"] option:selected').val(),         call: 'getcustomersemaillist',         nmsadmin: '<?php echo tep_session_id();?>'       }, response );     },     change: function (event, ui) {         if(!ui.item){             $("#customers_name").val("");         }     },     focus: function() {        return false;     },     select: function( event, ui ) {        var customer_id = ui.item.customer_id;       var customer_email = ui.item.customeremail;       console.log(ui);       $('#customer_id').val(customer_id);       $('#customer_email').val(customer_email);       var terms = split( this.value );        terms.pop();        terms.push( ui.item.value );        terms.push( "" );       this.value = terms.join( "" );       return false;     } }); 

i have edited code , working fine me. can please check below code.

$( "#customers_name" )   .bind( "keydown", function( event ) {     if ( event.keycode === $.ui.keycode.tab &&         $( ).autocomplete( "instance" ).menu.active ) {       event.preventdefault();     }   })   .autocomplete({     source: function( request, response ) {       $.getjson( "ajax_functions.php", {         term: extractlast( request.term ),         console: $('select[name="console"] option:selected').val(),         call: 'getcustomersemaillist',         nmsadmin: '<?php echo tep_session_id();?>',         datatype:'json',       },response ).fail(function(jqxhr, status, error){ document.location.href='login.php'; });     },     response: function(event, ui) {         console.log(ui.content);         if (ui.content.length === 0) {             alert("no results found");         }     },     change: function (event, ui) {         if(!ui.item){             $("#customers_name").val("");         }     },     focus: function() {        return false;     },     select: function( event, ui ) {        var customer_id = ui.item.customer_id;       var customer_email = ui.item.customeremail;       console.log(ui);       $('#customer_id').val(customer_id);       $('#customer_email').val(customer_email);       var terms = split( this.value );        terms.pop();        terms.push( ui.item.value );        terms.push( "" );       this.value = terms.join( "" );       return false;     },     error : function() { document.location.href='login.php';} }); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -