Reputation: 71
Default variable set var a = ''; var b = ''; var html =' <td>'+a+b+'</td>'
;
then I create another event use ajax
$('element').click(function(){
....
//when ajax was success change value of variable
a = 'webb';
b = 'sam';
// And append the variable "html"
$(div).append(html );
but the variable a & b is empty. why??
Upvotes: 0
Views: 116
Reputation: 10003
I think the problem is that you have assigned "html" variable value of "<td> + a + b + </td>" when a & b were empty and then never changed it. Try:
a = 'webb';
b = 'sam';
// And append the variable "html"
html =' <td>'+a+b+'</td>'
$(div).append(html);
Just to give some clarity: this is not related with variables being global or local. You get empty "<td></td>
" because variable "html" is assigned a value (i.e. it get's normal string value rather than a reference to a and b variables).
Upvotes: 1