I am creating a small domain availability checker. For that I will parse the desired domain into a form, and submit that to a PHP file with jQuery AJAX. However while I am looping through the different TLD's it suddenly gets undefined and I am not able to use the "TLD" for further processing within the loop. As far as I can read, it as something to do with the loop happening first and the requests made after, so I somehow have to freeze the index of my array. But I don't know how to do that.
This is my code:
$("input[name=submit]").click(function(){
        var getDomain = $("#domainsearch").val();
        var stripDomain = getDomain.split(".");
        var domain = stripDomain[0];
        var tlds = ["dk", "se", "com", "net"];
        for (var i = 0; i < tlds.length; i++ ) {
            var dataString = "domain=" + domain + "." + tlds[i];
            console.log(dataString);
            $.ajax({
                type: "POST",
                url: "search.php",
                data: dataString,
                success: function(data) {
                    console.log(domain + "." + tlds[i] + " is " + data);
                }
            });
        };
        return false;
    });
The printed console.log's looks like this:

 
     
     
    