Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Tuesday, January 25, 2011

JavaScript Error - Object Not Found

Problem:
When you refer JavaScript/css/images files, it will be referred properly and the code works fine in local machine. But you may get JavaScript error "Object Not Found" when deployed in web servers.


Solution:
Kindly use the  symbol to avoid this Object Not Found error to specify the root directory.


Sample Code:
The below code which generates "Object Not Found" JavaScript error,
<link href="/Content/Styles/MasterPage.css" rel="stylesheet" type="text/css" />
Or 
<link href="../Content/Styles/MasterPage.css" rel="stylesheet" type="text/css" />


Working Code:
Use  symbol before the / to refer the root level as shown below,
<link href="~/Content/Styles/MasterPage.css" rel="stylesheet" type="text/css" />
In addition, if you are working in MVC, use Url.Content to get absolute URL as shown below, 
<script src="<%= Url.Content("~/Scripts/jquery-1.4.4.js") %>" type="text/javascript">script>


Conclusion
Make a practice of referring any external files by using the ~ symbol in the root level to avoid Object Not Fund error.


Happy Coding


Thursday, December 23, 2010

"Object Expected" error in MVC JQuery autocomplete

Problem :-


I have been working in MVC and its very interesting to work with it. I just started working on JQuery. I have encountered this problem when implementing autocomplete to Text box in MVC with JQuery. The JavaScript error "Object Expected" will be coming when you reload the page. That means during first time load, there will be no problem. But if you click on paging and try to do autocomplete in text box. You could face this error in autocomplete statement.

Solution :-


Normally  we used to include the Jquery files by dragging to the page. When we drag the files, the following text will be added,

<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript">

The blue color text shows like the Scripts directory is placed inside one folder from the root. But its not like that. Its placed directly under the root.

So change that script include to the below one.

<script src="/Scripts/jquery-1.4.1.js" type="text/javascript">


This will solve your problem.


Conclusion :-


This may be the small issue but kill your time like anything. You won think the problem due to this script include tag. 


Happy Coding.. :)