I have a function in JavaScript, I'm trying to change the global var from a function, but it always returns the same initial value of 3:
For example: initial value 3, function value 0, but always warning 3.
var test = 3; jQuery.ajax({ type: "POST", url: "ajax_js.php", data: String, success: function(result){ test = result; if(result == 0){ $('input[name=user_name]').val(''); } } }); alert( test);
source share