I just confused with this problem. I had problem with variable value which inside $.post
function is different with the parent function $(element).each(function
, Here's my code :
$(document).ready(function() {
$(".list").each(function() {
var a = $(this).find("input.input-text").val();
console.log(a);
$.post("/Somewhere/path/").done(function(e) {
console.log(a);
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="list"><input type="text" class="input-text" value="30000"></div>
<div class="list"><input type="text" class="input-text" value="20000"></div>
<div class="list"><input type="text" class="input-text" value="10000"></div>
The value of a
variable in each function is normally shown, like
30000
20000
10000
but the value of a
variable inside $.post
function is returning the same value like
10000
10000
10000
I found alternative with declare a
variable inside $.post
function, but is there any another solution?