I have JavaScript using jQuery and AJAX which creates a dynamic array, which has some values used for AJAX request as below;
JavaScript
x
18
18
1
<script type="text/javascript">
2
var array = Array("y","y","x","y","y","y");
3
function updateBackground(cellId, titleId) {
4
var i = 0;
5
$.ajax({
6
type: "POST",
7
url: "ajax.php",
8
data: {
9
filename: Array(array[i], "testdata", $("#"+titleId).html())
10
},
11
success: function(response){
12
$("#"+cellId).css("background-image", "url('pdfthumb/" + response + "')");
13
}
14
});
15
i++;
16
}
17
</script>
18
The script is suppose to submit values in the array in array[i]
for each AJAX request. I made a variable var i
which auto increments.. But the script is not working.. The script works well if array[i]
is replaced by array[0]
or array[1]
etc..
How can I solve the syntax error?
Advertisement
Answer
I fixed it… Thank you so much @Jed, @Pointy, @Crozin, and @Lord Vader for helping me to figure it out…. 🙂
I just take var i = 0;
outside the loop…. above var array
like;
JavaScript
1
3
1
var i = 0;
2
var array = Array("y","y","x","y","y","x");
3