jQuery: How do I pass a value into an Ajax call?

Posted by Legend on Stack Overflow See other posts from Stack Overflow or by Legend
Published on 2010-06-04T02:40:25Z Indexed on 2010/06/07 0:52 UTC
Read the original article Hit count: 230

Filed under:
|

I am updating some div as follows:

for(var i = 0; i < data.length; i++) {
    var query = base_url + data[i];
    $.ajax({
        url: query,
        type: 'GET',
        dataType: 'jsonp',
        timeout: 2000,
        error: function() { self.html("Network Error"); },
        success: function(json) {
            $("#li" + i).html("<img src='" + json.result.list[0].url + "' />")
        }
    });
}

The value of i does not work inside the ajax call. I am trying to pass the value of i so that it can attach the element to the proper div. Can someone help me out?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery