0

I have AJAX use for loop to let array values in . and response will not response my source values, only have final result.

code:

var arrayD = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q"]

for (var i = 1; i < arrayD.length; i++) {
    var arrayValus = arrayD[i];
    $.ajax({
        type: "post",
        contentType: "application/json; charset=utf-8",
        url: "url.aspx/ABCstringPlus",
        data: "{to:'" + arrayValus + "'}",
        success: function (msg) {
            console.log(arrayValus);
        }, Error: function (msg) {
            alert('error');
        }
    })
}

I want to get my source values, but it all only get last array values "Q" ... even my parameter is "A" or "B"...

How do I to get my source parameter?

Vic
  • 758
  • 2
  • 15
  • 31
  • 1
    `console.log(country);` from where you are getting `country` variable here? – Guruprasad J Rao Oct 27 '15 at 03:47
  • Sorry, I forget to rename that , it's "arrayValus" not "country"... – Vic Oct 27 '15 at 03:53
  • Finally, I found answer : [closures](http://blog.taian.su/2012-10-17-explaining-javascript-scope-and-closures-by-robert-nyman/) – Vic Oct 28 '15 at 03:24
  • and Use this way to solved [AJax](http://stackoverflow.com/questions/10340134/passing-loop-count-into-ajax-success-anon-function) – Vic Oct 28 '15 at 03:26
  • Another [link](http://www.cnblogs.com/leoo2sk/archive/2010/12/19/ecmascript-scope.html) about Closures – Vic Nov 04 '15 at 07:23

0 Answers0