jquery - How to pass data's through ajax if that variable have any values -


the following code ajax,

$( ".location" ).on( "click", function(){     var loc = $('.location:checked').map(function(_, el) {         return $(el).val();     }).get();     if($(".hedu").is(':checked'))     {         var edu = $('.hedu:checked').map(function(_, el) {             return $(el).val();         }).get();     }     $.ajax({         url: 'search_cv_result',         type: 'get',         data: {             edu:edu,             loc: loc,             fltr:"ftr"         },         success: function(data) {         $('.course_list').html(data);         }     }); }); 

here,i pass loc variable , edu variable ..

the edu value either null or not null.

if null don't want send edu value through ajax..

i tried this..

        data: {             if(edu != ''){             edu:edu,}             loc: loc,             fltr:"ftr"         }, 

but think it's not correct method..and show me error..

how should this..someone me..

    if (loc === 'undefined' || loc === null) {         var _data  = { loc: loc, fltr: 'ftr' };     }      else {         var _data = { edu: edu, loc: loc, fltr: 'ftr' };     }      $.ajax({        url: 'search_cv_result',         type: 'get',         data: _data,         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: function (msg) {             alert('in ajax');         }     }); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -