-3

I have update from jQuery 1.7.1 to 1.10.2 and now below problem appears in jquery.unobtrusive-ajax.js:

$("a[data-ajax=true]").live("click", function (evt) {
    evt.preventDefault();
    asyncRequest(this, {
        url: this.href,
        type: "GET",
        data: []
    });
});

the issue is in live. it says $("a[data-ajax=true]") does not accept method or property live.

How to solve this? should I upgrade jquer.unobtrusive-ajax.js or something like this?

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
Willy
  • 9,848
  • 22
  • 141
  • 284
  • 4
    `live` is deprecated, use [`on`](http://api.jquery.com/on/) instead – Krzysiek Sep 23 '13 at 16:06
  • Dear don't just expect everything to work when you upgrade jquery read the changelog. If you read the live docs you ll see that it was removed in jquery 1.9 http://api.jquery.com/live/ . Use on instead. – Patsy Issa Sep 23 '13 at 16:06
  • Run the Migrate plugin. https://github.com/jquery/jquery-migrate/ – j08691 Sep 23 '13 at 16:07

4 Answers4

7

Read the docs please, live was removed and replaced with .on()

$(document).on("click", "a[data-ajax=true]", function (evt) {

document is the container that houses the dynamic content.

tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • Sorry, but i am completely new on jQuery. Should I upgrade by modifying the deprecated functions manually in this file rather than upgrading the entire file? Isn't there upgrades of jquery.unobtrusive-ajax.js to download from anywhere? – Willy Sep 23 '13 at 16:17
3

the method .live has been deprecated in version 1.7 and removed later you should use .on

Check the documentation:

http://api.jquery.com/live/

If you are using plugins dependent on live then I would continue to use version 1.7

Richard
  • 21,728
  • 13
  • 62
  • 101
3

It's also good to know about the jQuery Migrate Plugin. It's from jQuery itself, and available directly from their GitHub.

The purpose of the plugin is to "to simplify the transition from older versions of jQuery. The plugin restores deprecated features and behaviors so that older code will still run properly on jQuery 1.9 and later. Use the uncompressed development version to diagnose compatiblity issues, it will generate warnings on the console that you can use to identify and fix problems."

Source: jQuery download page

cssyphus
  • 37,875
  • 18
  • 96
  • 111
1

use .on()

$(document).on("click", "a[data-ajax=true]", function (evt) {

See .live() has been deprecated in version 1.7 and removed in 1.9.

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107