javascript - JSON is null but data passes to success in ajax -


i'm running problem in ajax. scenario is: verify if user available or not when typing email. create function in javascript ajax script within it. here code :

$('#username').keyup(function () {   var email = $(this).val();    $.ajax({     type: 'get',     url: 'http://localhost:8080/meublestunisv4/web/app_dev.php/email-verification/' + email,     datatype: "json",     beforesend: function () {       $('#email_status').html('<img id="loading" src ="{{ asset('bundles/theme_front_end/images/loading.gif')}}"></img>');      },     success: function (data) {       $('#email_status').remove();       $('#email_status').html('<img id="loading" src ="{{ asset('bundles/theme_front_end/images/green_tick.png')}}"></img>');     }    }); }); 

my problem : when type words calls function of keyup passes success if data null. let pass success if data correctly done. thank you.

try following..hope works want...

$('#username').keyup(function () {             var email = $(this).val();             if(email != "") {              $.ajax({                 type: 'get',                 url: 'http://localhost:8080/meublestunisv4/web/app_dev.php/email-verification/' + email,                 datatype: "json",                 beforesend: function () {                     $('#email_status').html('<img id="loading" src ="{{ asset('bundles/theme_front_end/images/loading.gif')}}"></img>');                  },                 success: function (data) {                     // check response data...                    if(data == 'true') {                          $('#email_status').remove();                        $('#email_status').html('<img id="loading" src ="{{ asset('bundles/theme_front_end/images/green_tick.png')}}"></img>');                      }                  }              });          }      });  

Comments