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
Post a Comment