0

Sometimes before, I use the function .load() as

// document load
$(document).load(function() {
    // ... code ...
});

but now, its doesn't work.

I just use the function .ready()

// document ready
$(document).ready(function() {
    // ...code...
});

the function .load() is used as a part of ajax now.

I remember that there is something defferent between the two function.Now canceled the .load(), are there the same ?

The code as:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script type="text/javascript" src="jquery-2.2.3.js"></script>

<script>
    $(document).ready(function() {
        console.log("ready");
    });

    $(document).load(function() {
        console.log("load");
    });
</script>

</head>
<body>

</body>
</html>

and the console shows : "ready"

the function .load() doesn't work!

Oolong
  • 171
  • 1
  • 1
  • 9
  • `$(document).load(fn)` still works fine, so I'm not sure what you're asking. Note however that the `load()` event handler is being deprecated. If you want to future proof your code use `$(document).on('load', fn);`. The functionality it provides is identical, however. – Rory McCrossan Apr 27 '16 at 07:34
  • "*When [did] JQuery cancel the .load() function?*" - answer: they didn't [they haven't] – freedomn-m Apr 27 '16 at 07:44

2 Answers2

1

There are two function headers of load()

$('selector').load(function () {}); // #1
$('selector').load('url', {data}, function () {}); //2

#1 will execute code when element has loaded up.
#2 will call ajax for provided url with (optional) {data} object and will replace content of $('selector') and executes callback function.

If looking for difference between .load(function () {}) and .ready(function () {}), than check this question

Community
  • 1
  • 1
Justinas
  • 41,402
  • 5
  • 66
  • 96
0

Both are different.

When you are using load() then It will call after loading all the elements of the Page like (Image).

When you are using ready() then It will call after DOM is ready.

If you want to bind the ajax event then please look at the on and delegate as well as you could also prefer the live method but it is deprecated.

Parag Kuhikar
  • 485
  • 2
  • 6
  • 17