According to jQuery load() method api:
.load( url [, data] [, complete(responseText, textStatus, XMLHttpRequest)] )
- 1st parameter is url
- 2nd parameter is map or string that is sent to the server
- 3rd parameter is callback function.
With the working example below
$('#result').load('ajax/test.html', function() {
alert('Load was performed.');
});
it supplies arguments of ‘url’ and ‘callback function’, [data] argument is skipped.
Shouldn’t the example code treat the callback function as [data] argument (2nd parameter) ? Because of the order that parameters defined in the API . By following the API, 1st is url, 2nd is data, 3rd is callback.
I don’t get why the code would work. Very confused.
It is very clearly written in the jQuery source code.
https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js
Search for
load: function( url, params, callback )It checks for the params (second parameter) and if it exist, It will call the
isFunctionmethod which internally check the type of the argument and return true if it is a function. The rest you know….This is how
isFunctionlooks like