0

I've used dialog box using Jquery in my MVC form.

In my View :

 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
 <script>
     $(function () {
         $("#dialog").dialog({
             autoOpen: false,
             show: {
                 effect: "blind",
                 duration: 1000
             },
             hide: {
                 effect: "explode",
                 duration: 1000
             }
         });
         $("#opener").click(function () {
             $("#dialog").dialog("open");
         });
     });
</script>

@using (Html.BeginForm())
{ 
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
}

I tried to debug with Firebug and it shows the Error

TypeError: $(...).live is not a function


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

When i click the button the jquery function is executed but it doesn't display the Dialog Box.How do i solve this?

King_Fisher
  • 1,171
  • 8
  • 21
  • 51

1 Answers1

1

Use on instead of live as you're using jQuery 1.10.2 and in this version the method live deprecated for use:

$("a[data-ajax=true]").on("click", function (evt) {
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • but I don't have that live – King_Fisher Dec 13 '14 at 17:42
  • I dont have this - $("a[data-ajax=true]").live("click", function (evt) – King_Fisher Dec 13 '14 at 17:43
  • Its shows error at this file -@Scripts.Render("~/bundles/modernizr") do i need this ? – King_Fisher Dec 13 '14 at 17:44
  • 1
    @King_Fisher the `.live()` function is obsolete and it's no longer supported by the library. This answer is telling you that there's a new API and in fact it linked to the documentation for it. – Pointy Dec 13 '14 at 17:45
  • @Pointy I just referred from here [link](http://jqueryui.com/dialog/#animated) – King_Fisher Dec 13 '14 at 17:47
  • @Pointy The problem is that the offending code is not in OP's code. See my comments on the question for more details. – JLRishe Dec 13 '14 at 17:49
  • 1
    @King_Fisher You probably don't need modernizr unless you are actively using it. However, I doubt that it is actually the source of the problem. – JLRishe Dec 13 '14 at 17:50
  • @JLRishe Modernizr doesn't have jQuery dependencies, so it's not coming from there. *edit* oh I see - nevermind. – Pointy Dec 13 '14 at 17:57
  • @JLRishe I Comment that but still the same .I'm novice so guide me sir – King_Fisher Dec 13 '14 at 17:58
  • @Bhojendra-C-LinkNepal: If it's using `.live()`, then the elements probably don't exist when the code runs. – six fingered man Dec 13 '14 at 18:02
  • @King_Fisher As I already pointed out, the problem is in jQuery unobtrusive Ajax, not modernizr. I would suggest getting the latest version of jQuery Unobtrusive Ajax and jQuery Unobtrusive Validation from NuGet. The latest versions of those have already been properly updated to use `.on()`. – JLRishe Dec 13 '14 at 18:07
  • @JLRishe I have downloaded jquery.unobtrusive-ajax.js and jquery.validate.unobtrusive.js .Do i have to Include or replace anywhere ? – King_Fisher Dec 13 '14 at 18:19
  • @King_Fisher If you downloaded them using NuGet, then you should probably be good to go. – JLRishe Dec 13 '14 at 18:25
  • @JLRishe yes I'm. Tools ->Library Package Manager->Manage Nuget pakage for solution -> and i searched with online and downloaded now I can see those file in my Project Script Folder – King_Fisher Dec 13 '14 at 18:29
  • @King_Fisher Well, is the problem fixed? – JLRishe Dec 13 '14 at 18:30
  • @JLRishe yes, Error Fixed ,but I don't see any Dialog box sir . – King_Fisher Dec 13 '14 at 18:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66823/discussion-between-king-fisher-and-jlrishe). – King_Fisher Dec 13 '14 at 18:40