'Sys' is undefined javascript error - javascript

I am getting the following error:
Microsoft JScript runtime error: 'Sys'
is undefined
While trying to execute:
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
//ERROR IN THIS LINE!!!
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onUpdated());
function onUpdated() {
// get the update progress div
var pnlPopup = $get("div2");
// make it invisible
}
</script>
</head>

Ensure you have a Scriptmanager on the page and the script is below the scriptmanager. Maybe try to put your script tag into body and see what happens.
I don't know how you can fix that that its not in the body, but maybe there is a callback from Sys when its loaded
You don't need brackets to tell which function is neeeded:
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onUpdated);

If that is your full code, then the problem is that the Microsoft AJAX libraries aren't being included. If it isn't your full code, then you need to post more as it's a little hard to get beyond the fact that the library isn't included. Somewhere in your file -- prior to the line you are having problems with you need to have a javascript include like:
<script type="text/javascript" src="/scripts/MicrosoftAjax.js" />
As well as probably a few others.
Note: I'm talking about the generated source. Showing more complete markup would probably also suffice.

I'm a bit late to the discussion here, but a simple solution is to create a "ASP.NET AJAX-Enabled Web Site" in Visual Studio and then merge the web.config from that site with your existing site.
In this way you get all the configuration you need without having to carefully read through a lot of docs. Speed is of the essence and all that :)

You can fix this issue by setting the EnableCDN property to "true".refer this link

I had the same issue , after all findings I found that the required script files ("MicrosoftAjax.js", "WebForms.js","jquery", "bootstrap" etc..) were not loaded properly which was causing me 3 errors "Sys' is undefined", "webform_docallback is undefined" and "webform_initcallback' is undefined", my actual problem was I had reference to these files which where not included in my propject, my bad I have not noticed it, I have tried all the possible solutions from the internet before I really found that my js files were not included and thats the reason its not loaded properly.
Hope this helps..

Related

JQuery CDN not working, and local JS script not seen

I can't understand this for the life of me. I normally work with Python, but am trying to dabble a bit in web development with JQuery. I've used the CDN from google, and have done everything from putting the script below the footer (A site I found said that was the best spot), to moving it up into the header (every other site I've been to since says that is the best spot), and nothing works.
From the error in the inspection tools 'Loading failed for the with source “http://localhost:63342/HTML/Omnifood/resources/javascript/script.js”.' It suggests to me that it can't even find the .js file I created to hold my code, but it is there, defined. (See screenshots attached)
Any help getting this sorted out would be appreciated.
Screenshot of HTML and file structure, as well as error in inspection tool:
Edit: The issue has been resolved in so far as the folder has been moved to the correct location (/resources/javascript/script.js), I even went in and added type="text/javascript" to all the script files just in case. Now when attempting to run script with following JQuery code:
$(document).ready(function() {
$('h1').click(function() {
$(this).css('background-color', '#ff0000')
})
});
I get the following errors in inspection tool:
The path is wrong http://localhost:63342/HTML/Omnifood/resources/javascript/script.js
your script.js is at
http://localhost:63342/HTML/Omnifood/vendors/javascript/script.js

Undefined not a function: how to get LABjs to work with jQuery scripts

I'm trying to improve the load time of my web page using LABjs. However I'm getting 'Undefined not a function' in relation to jQuery.cookie('mycookie') which I'm using in my own jQuery script.
I'd be grateful for some advice on how to implement LABjs to deal with this as I don't quite understand the documentation.
Here's the code I have so far:
HTML
I have jQuery and LAB.min.js in the footer of my HTML page
<script type="text/javascript" src="myfolder/jquery1.9.1.js"></script>
<script type="text/javascript" src="myfolder/LAB.min.js"></script>
LAB.min.js file
Here I load my scripts in order. ratings.js depends on jquery-cookie.js, so I've included a wait() first to make sure that jquery-cookie.js is loaded first.
//ALL THE LABjs code is here, but not included on this post!
$LAB.setGlobalDefaults({Debug:true});
.script("myfolder/bootstrap.min.js")
.script("myfolder/jquery-cookie.js")
.wait()
.script("myfolder/ratings.js");
ratings.js
ratings.js is a long piece of code contained within the jQuery(document).ready function.
jQuery(document).ready(function() {
//LOTS OF CODE HERE
if(jQuery.cookie('mycookie')==null){
//LOTS OF CODE HERE
}
//LOTS OF CODE HERE
});
I'm getting an error in ratings.js relating to the line of code containing jQuery.cookie('mycookie'). It says "Uncaught type error: undefined is not a function"
From what I understand, jQuery.cookie() isn’t yet defined when I try to pass it to .wait(). What is the best way to get this to work, keeping in mind that I want to keep ratings.js in a separate js file because it contains a lot of code and is one of many similar js files that also throw up the same error when I load them with LABjs.
Many thanks!
Katie
You should be able to remove the link to jQuery in your HTML and just have LABJS to load all of the scripts. This will load jQuery before Bootstrap or your plugin:
$LAB
.setGlobalDefaults({Debug:true}) // removed semi-colon
.script("myfolder/jquery1.9.1.js")
.wait()
.script("myfolder/bootstrap.min.js")
.script("myfolder/jquery-cookie.js")
.wait()
.script("myfolder/ratings.js");
(Note that you had a semicolon in your code that was likely breaking something too):

Netbeans autocompletion not fully working with current jQuery.js (v1.8.0)

I just started using netbeans (NetBeans IDE 7.2 (Build 201207171143) under Win7/64bit) to try out jQuery developement. Especially the autocompletion seemed very handy..
I used this tutorial: http://netbeans.org/kb/docs/web/js-toolkits-jquery.html
I did everything like in this tutorial but took the current version of jQuery.js (v1.8.0) instead of the older 1.4.2-revision.
Lets look at the following code snipped:
<script type="text/javascript">
$(document).ready(function(){
$("h1").click(function(){ alert ("HI!"); });
});
</script>
The autocompletion works for "$(document)." and suggests "ready". So far, so good...
The 3rd line starts with "$("h1")." after that selector followed by "." I get a lot of suggestions but not for "click"; When I use the older jQuery-1.4.2.js it works as seen in the following screenshot of the tutorial: http://netbeans.org/images_www/articles/69/web/js-toolkits-jquery/code-completion.png
Questions:
What's actually the problem here?
Can we somehow get this working with the current version of jQuery? If so: How?
Who's potentially in charge here ... bug in jQuery or netbeans?
Regards,
Stefan
--- update ---
The problem only occurs if you add a <script type="text/javascript" src="js/jquery.js"></script> to the source code. If you omit the include, it's working as it should.
So this seems to be an issue of Netbeans. And lead us to the following adapted question:
Question: Not including the jquery.js is just a workaround. Is there a way to fix that? Maybe it's needed that we disable some "auto-include-everything" option somewhere in the project?
--- update #2 : SOLUTION ---
It's even the name of the included script <script type="text/javascript" src="jq.js"></script> works, but any resource name ending in 'jquery.js' don't work, whereas <script type="text/javascript" src="jquery-1.8.0.js"></script> worked!
So it's actually a kind of bug in Netbeans, that is caused by some hardcoded stuff. And the solution is to rename the JavaScript file in a way that it e.g. still includes the revision.
Looks like you're using a minified version of jQuery, because you're likely getting code completition from JS core, so you need to include in your project the development version or both (development and minified), if you're pushing code to production, to get jQuery code completition and API especifications. Watch this:
One possible problem might be that click() has been depreciated in favor of on() Of course click() without parameters is still used to fire the event, so I'm probably wrong but see if this autocompletes correctly:
$("h1").on("click",function(){ alert ("HI!"); });
Note: on() was introduced in version 1.7

Why the copied HTML doesn't look like the original HTML?

I copied the generated source code (View Source -> View Generated Source in the Firefox Web Developer Toolbar) of Google's Keyword Tool page to a new HTML file.
But, when I open this new file, some of the items looks stretched for some reason:
The original website looks like this:
I guess that Google create some elements and set various attributes using Javascript, but I copied the page after it has been generated. So, why is this difference?
UPDATE 1
The only JS/CSS file, which is not given as a full path, is:
<script language="javascript" src="/cues/cues.js">
I tried replace this with:
<script language="javascript">
Contents of '/cues/cues.js' here
</script>
but it didn't help.
UPDATE 2
In the browser's error console I found the following 2 errors:
Error: com_google_ads_apps_servers_cues_CuesRelease is not defined
Source File: https://adwords.google.com/cues/768DAEDDB2193AB5B05B9C6A01394D78.cache.js
Line: 1
Error: com_google_ads_apps_targetingideas_client_TargetingIdeas is not defined
Source File: https://adwords.google.com/o/Targeting/756D6AF3BB4DD4A68315E34F50C2BC7E.cache.js
Line: 1
Any ideas why these errors appear?
UPDATE 3
Apparently, the reason is that the DOCTYPE declaration is missing. After I added <!DOCTYPE html> to the stretched version, it solved the problem. Can anyone explain why?
When you save a page, you only get the version of HTML served from the server in its original form. Any mods to the DOM made after load using JS will not be part of the save.
EDIT
I could not trace out the exact reason for the error as the code is really cryptic! In any case, if all you want is to be able to reproduce the exact page offline, then you can do a 'save page as..' from your browser (choose web page, complete). I tried this with FF as well as Chrome and it is working fine in both cases. While opening the saved page, it might be best not to use IE as its a certified choker when it comes to even the slightest error in code. :)
The most likely reason for the error is an cross-domain AJAX security exception (fired when the calling client side script and called server side script are from different domains). The 2 variables namely, com_google_ads_apps_servers_cues_CuesRelease and com_google_ads_apps_targetingideas_client_TargetingIdeas seems to be initialized using the return of some AJAX call (which couldn't execute bcoz of the secu excep), and as a result remain as undefined.
You must be missing some css and js which is not on the page but referred from somewhere else.
The most probable reason is that the CSS and the corresponding images that might be referred within it are not getting applied correctly.
Check the paths of the CSS and for the images (background) within the CSS...You might need to correct the paths to fix the issue.

Is the load order for external javascript files different in IE8 compared to IE7?

I ask because I'm running an application in which I load an external script file in the HEAD section of the page, and then attempt to call a function from it in the onLoad section of the BODY tag.
external.js
function someFunction()
{
alert("Some message");
}
myPage.html
<html>
<head>
<script type="text/javascript" language="javascript" src="external.js"></script>
</head>
<body onLoad="someFunction();">
</body>
</html>
Using the developer tools in IE8, I get an exception thrown at the onLoad statement because, apparently, the external javascript file hasn't been loaded yet.
I haven't had this problem come up in IE7 before, thus my question.
Did they change the load order between IE7 and IE8? If so, is there a better way to do this? (the real function references many other functions and constants, which look much better in an external file)
Thanks,
B.J.
Well, I feel pretty stupid actually.
Turns out the problem wasn't with the load order. The problem was that the external javascript file had a syntax error in one of its functions, and apparently when the exception was thrown it completely invalidated the whole file, thus making the rest of the functions unavailable to the main page.
I'm not sure if this behavior is different in IE8 compared to IE7, but anyway, that was the real problem.
Thanks for your reply.
B.J.
I doubt very much that his has changed it would break a considerable number of websites.
Try this (without using the developer tools):-
<body onload="alert(somefunction)">
this shouldn't break and will tell you whether at the point onload executes whether the identifier somefunction can be seen.
Assuming that what you think is happening is what is happening, you should try to attach the body.onLoad later on.
To simplify things, you can do it with Prototype (including prototype, of course) with
Event.observe(window, 'load', function() { myFunction.init() });
or JQuery (including JQuery) with
$(document).ready(function(){
// Your code here...
});
I think there is a pure Javascript way to do this, but the problem is that the body element won't exist yet, so it's rough...
That said, I have had no problems running body onload in Javascript with IE8, and putting it right into the body tag, using external files. I'm going to test that right now out of curiosity, and I'll report back.
Edit: There's no problem doing the onload from an external file. However, while we're at it, you might want to get to know JQuery, Prototype or Scriptaculous :)

Categories