javascript - jQuery variable is not being populated before ajax function. -


please take @ [fiddle][1].

i trying tables selected checkbox contained in given div. tables sent variable $content ajax function before being sent mail function.

however, when click send button, getting error - content not defined.

 jquery('#search-query-send').click(function(){                                       jquery('.selectthis input:checked').each(function() {                     var content = jquery(this).parents('div.apartment-entry-container').html();                     var email = jquery('#email').val();                 });                   jquery.ajax({                     url:"http://www.greenmonkeypublicrelations.com/scpads/wp-admin/admin-ajax.php",                     type:'post',                     data:'action=apartmentsearchemail&email=' + email + '&content=' + content,                                                         success:function(result){                     //got back, assign fields.                                              alert('your message has been sent.');                         console.log(result);                                  }                    });              });  

the variable content here local variable, , contains current table's html. if want send them together, have append/join values using +=:

jquery('#search-query-send').click(function() {    var content = '', email = '';    jquery('.selectthis input:checked').each(function() {     content += jquery(this).parents('div.apartment-entry-container').html();     var email += jquery('#email').val();   });    jquery.ajax({     url: "http://www.greenmonkeypublicrelations.com/scpads/wp-admin/admin-ajax.php",     type: 'post',     data: 'action=apartmentsearchemail&email=' + email + '&content=' + content,     success: function(result) {       //got back, assign fields.                            alert('your message has been sent.');       console.log(result);     }   }); }); 

however, sending html code via method not advisable. try post instead?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -