简体   繁体   中英

jquery autocomplete not working in VS2012 but works fine in VS2010

I was trying to use autocomplete and it is not working in VS2012. So, i took a sample from jQuery( http://jqueryui.com/autocomplete/#default ) and pasted the same in VS2012 and VS2010. It works fine in 2010 but throws exception in 2012.

Any idea why this is happening?

To avoid any case of plugins or scripts mismatch, I used the cdn references as given by jquery site.

Here is the source code I have used. This is the only content and nothing else has been added in VS2012 and VS2010

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Autocomplete - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
        ];
        $( "#tags" ).autocomplete({
            source: availableTags
        });
    });
    </script>
</head>
<body>

<div class="ui-widget">
    <label for="tags">Tags: </label>
    <input id="tags" />
</div>


</body>
</html>

EDIT: I have observed that in VS2012 it is attaching the default layout if none mentioned. Again, if we remove the "@RenderSection("scripts", false);" in the layout.cshtml file, things will start working.

Anyone, knows why is this?

I got this.

Only change I did was to move the following piece of code in _Layout.cshtml from bottom to the head section.

"@Scripts.Render("~/bundles/jquery")"

:) Happy now. Wasted almost a day on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM