Thursday, August 21, 2014

JavaScript runtime error: '$' is undefined – Azure web role and jQuery

I wanted to use jQuery in my Azure ASP.Net web role. I created a cloud service project and then added one asp.net web role in it.
Then to use jQuery I had decided to use HTML page. Therefore I added HTML page in my wen role sample. I wrote some jQuery code and at runtime I received error as -
JavaScript runtime error: '$' is undefined
This error is encountered because the jQuery version is referenced in HTML page however it’s path is incorrect.
If you open the solution explorer you will find that jQuery is already added in your web role project under the folder Scripts as shown below –

However in HTML page it is referenced with incorrect path as shown below –

The folder js as referenced in above screenshot does not exists and file jQuery files are present in Scripts folder. Therefore I changed the path of jQuery file as below –
<script src="Scripts/jquery-1.10.2.min.js"></script>
And you are done. No runtime error was displayed after this change.
Hope this helps.
Cheers!!!

No comments:

Post a Comment