ASP.NET MVC AJAX Sys is an undefined error

I get the error "JScript error for Microsoft JScript:" Sys "undefined error" on one of my pages in an MVC application when I try to call AJAX. An AJAX call is made from a partial view that is embedded in more than one page. It works great on all pages except one. I have read messages pointing to the parameters of the web.config file and the .axd associations as possible solutions, but the application is configured correctly in the web.config file, and the .axd associations are also correct in IIS. Plus, it works great on all pages that use this partial view, except for one. It acts just like AJAX libraries are not loading for this single page.

Links to script files are in the general site.master file. All pages, including those that do not work, link to the same main page.

Any ideas? I’ve been working on this for two days now. Thank you

EDIT: As Sam showed below, it looks like the AJAX call is triggered before the AJAX libraries can load. But the AJAX call is launched by the submit button long after the page is displayed, so AJAX libraries have enough time to load - sorry for not giving enough information for the first time.

+6
asp.net-mvc asp.net-ajax
source share
8 answers

Load the page in Firefox, then use Firebug to check the page - you can see all the loaded individual scripts, as well as all the network requests that were issued, and whether they were successful or not. This is better than trying to fix the problem from a server perspective.

If you use IE8, you can use the Developer Tools window, but I think Firebug is better - both tools support JavaScript debugging.

The most likely problem is that you execute the script in your partial view before the scripts on which it depends have the ability to load - make sure that any script calls that you have in your partial view will be executed only after page loading, not immediately during loading.

+3
source share

Just in case ... use the following to avoid traffic issues

<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.debug.js") %>" type="text/javascript"></script> <script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.debug.js") %>" type="text/javascript"></script> 

Source: http://msdn.microsoft.com/en-us/library/dd381533.aspx

Thanks Arty

+16
source share

In web.config add the following line of code to the appsettings tag:

 <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
+16
source share

All of the above cases are approved. But sometimes the developer forgets to add javascript files for ajax. So check this out.

+2
source share

Add to web.cofig in the section:

  <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/> 

  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 

0
source share

Regarding your answer to Sam, one thing that I have noticed in many MVC applications is that people do not know how to deal with the ambiguity of relative paths and application / runtime. For example, rewriting URLs pretty much ensures that a particular page can be displayed at different depths than you expected, so ../../images will point elsewhere depending on whether you are viewing /products/widget or /products/widget/12345 , although the view may be the same. As Artie noted, the best way to handle this is to let the engine do the work for you using the URL utility and application-specific paths that will be fixed by the application regardless of context.

0
source share

I also found that using the following works with ASP.NET MVC2.

Instead of using MicrosoftMvcAjax.js you are using MicrosoftMvcValidation.js

Hope this helps someone.

0
source share

You can mostly be absent: MicrosoftMvcAjax. , MicrosoftMvcValidation.debug and MicrosoftMvcValidation Links to JS files.

Take the following steps:

  • PM> Install-Package MicrosoftAjax

  • PM> Install-Package MicrosoftMvcAjax.Mvc5

  • Include them in bundleconfig as shown below:

     bundles.Add(new ScriptBundle("~/bundles/mvcFoolProof") .Include("~/Scripts/MicrosoftAjax*", "~/Scripts/MicrosoftMvcAjax*", "~/Scripts/MicrosoftMvcValidation*", "~/Scripts/mvcfoolproof*", "~/Scripts/MvcFoolproofJQueryValidation*", "~/Scripts/MvcFoolproofValidation*")); 

Now it should work without errors.

0
source share

All Articles