I have edited this question to clarify that this question does not relate to how to return a value from an ajax function call. It is asking why, when only 2 arguments are passed to $getJSON, the 2nd argument appears to be treated as though it were the 3ed. Having said that, please consider the following snippet of code:
<script>
var fName;
$.getJSON("work1.json", json);
function json(data)
{
fName = data['fname'];
}
</script>
Note that the $.getJASON function (which has one mandatory and 2 optional parameters) is given only 2 arguments. The first parameter is the mandatory "url" parameter. It is my understanding that the 2nd parameter is for data sent to the server and the 3ed parameter specifies the function to run if the request succeeds. Since only 2 arguments are passed, I would think that they would be for the 1st and 2nd parameters respectively. The first one is clearly the url. The 2nd one is behaving as though it were the 3ed parameter. Why is that? I thought that arguments passed to a function were assigned to the function's parameters in sequential order until exhausted. What am I missing?