Title: Passing parameters to an anoynmous function in AJAX call
Tags: javascript;jquery;ajax;anonymous-function
Question: I'd like to load items from an XML file and display them on a webpage via AJAX and limit the output via a date range. However I am struggling to pass the parameters to the anonymous function. All tries to hand over the parameter 'displayDateLimit' have ended in syntax errors. Any idea how to do this? 

In addition to that: If do not pass the the parameter I get an incremented counter for inpTest instead. Why does this happen?

```// loads XML to Div-Element.
function loadItemsToBox(id) 
{
    var boxElement = document.getElementById('someid');
    if (!boxElement){ return;}

    xmlUrl = 'someurl'];

    displayDateLimit = new Date().getTime();
    displayDateLimit -= 3600*1000;

    $.ajax({
        type: "GET",
        url: xmlUrl,
        dataType: "xml",

        success: function (xml) {

        var content = "";


         $(xml).find("item").each(function (inpTest) { // or "item" or whatever suits your feed
                var el = $(this);
                content += "<p&gt;";
                content += el.find("title").text() + "<br&gt;";
                content += "<br&gt;DateLimit: " + inpTest;
                content += "</p&gt;";
            })(displayDateLimit);
            boxElement.innerHTML = content;
        },
        error : function(xhr, textStatus, errorThrown ) 
        {
        // some errorhandling
        }
    });
}
```

Comment: You can define `displayDateLimit` outside the function, as an external var, and leave the function without parameters.

Comment: Please refer to `.each` documentation: http://api.jquery.com/each/. You don't need to invoke the function you are supplying. The documentation also answers why `inpTest` results in a counter.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:12/18/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery><ajax><anonymous-function>', 'Title': 'Passing parameters to an anoynmous function in AJAX call', 'ViewCount': 95, 'id': 47869832, 'user_AboutMe': None, 'user_AccountId': 12522677.0, 'user_DisplayName': 'Ralph W', 'user_Reputation': 31.0, 'user_Views': 2.0, 'user_id': 9113520.0}}