Solved

jQuery in Visual Studio 2010 not working

Posted on 2011-02-11
8
730 Views
Last Modified: 2012-05-11
Greetings, experts.

I am new to jQuery and decided to take the plunge.  I use Visual Studio 2010 ASP.NET for web development.

I downloaded the newest version of jQuery, 1.5, and added the file to the project.  I also found a version of the -vsdoc for 1.5 and added it in the same way.  The jQuery Intellisense seems to work fine.

After following all the steps for the typical "Hello World" test, nothing happens.

What have I missed?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Text-jQuery.aspx.vb" Inherits="Text_jQuery" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="scripts/jquery-1.5.min.js" type="text/javascript"></script>
    <script src="scripts/jquery-1.5-vsdoc.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("a").click(function () {
                alert("Hello World!");
            });
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <a href="#">Click Here</a>
    </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:ewolsing
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 34872588
Mmm... if you add the attribute language="javascript"?
0
 

Author Comment

by:ewolsing
ID: 34872617
jorge toriz:

I added, language="javascript", to the script tag containing the Hello World jQuery code, but to no avail.
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 34872857
<script src="scripts/jquery-1.5.min.js" type="text/javascript" language="javascript"></script>
<script src="scripts/jquery-1.5-vsdoc.js" type="text/javascript" language="javascript"></script>

Mmm... can you post the HTML result of your execution?
0
 

Author Comment

by:ewolsing
ID: 34873047
I added, language="javascript", to the tags defining the location of the jQuery libraries.

I executed the page and clicked the link, but still did not receive the expected alert box.

Per request, the HTML received *after* I clicked the link is included.  I hope it helps.  I've been scratching my head on this for the last several hours.  From everything I've read, it should work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title>

    <script src="scripts/jquery-1.5.min.js" type="text/javascript" language="javascript"></script>
    <script src="scripts/jquery-1.5-vsdoc.js" type="text/javascript" language="javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("a").click(function () {
                alert("Hello World!");
            });
        });
    </script>

</head>
<body>
    <form name="form1" method="post" action="Text-jQuery.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZEuZOv2bq3N7hsYmQUVPH9OqZ1C3xiqDh1uS1F+Iy7wd" />
</div>

    <div>
        <a href="#">Click Here</a>
    </div>
    </form>

</body>
</html>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:jorge_toriz
ID: 34873215
When you run your test, there must be a ASP .NET Development Server... as an example, is suppose that is "http://localhost:12345/YouTest/Default.aspx"

If you visit "http://localhost:12345/YourTest/scripts/jquery-1.5.min.js" and "http://localhost:12345/YourTest/scripts/jquery-1.5-vsdoc.js"... do you get the scripts?
0
 

Author Comment

by:ewolsing
ID: 34873645
I checked that the directories in which the scripts are located are available to ASP.NET.  As you suggeseted, I attempted to access the jQuery libraries from the address bar of my browser and did so successfully.  When I entered the address, the jQuery library I selected displayed with no problem.

That suggests it's not an ASP.NET directory access issue.
0
 
LVL 15

Accepted Solution

by:
jorge_toriz earned 250 total points
ID: 34873957
I have created an HTML page with the code that you posted, but I don't have the vsdoc file, so I didn't put that reference... if you remove that reference still not working?
0
 

Author Comment

by:ewolsing
ID: 34874078
Wow!  I commented out the vsdoc reference and it worked!

I suppose my next question is how I can retain the intellisense functionality without having to repeatedly comment and un-comment the vsdoc reference?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now