How can I return a variable from a $.getJSON function I want to return StudentId to use elsewhere outside of the scope of the $.getJSON() j.getJSON(url, data, function(result) { var studentId = result.Something; }); //use studentId here I would imagine this has to do with scoping, but it doesn't seem to work the same way c# does Solution: Yeah, my previous answer does not work because I didn't pay any attention to your code. :) The problem is that the anonymous function is a callback function - i.e. getJSON is
undefined
How do I include a JavaScript file in another JavaScript file? Is there something in JavaScript similar to @import in CSS that allows you to include a JavaScript file inside another JavaScript file? Solution: JavaScript has no import, include, or require. (Update 2015: it does now with ES6 modules) There are other ways for JavaScript to include external JavaScript contents, though. Ajax Loading Load an additional script with an Ajax call and then use eval. This is the most straightforward way, but it is limited to your domain because
undefined
How to implement file upload progress bar on web? I would like display something more meaningful that animated gif while users upload file to my web application. What possibilities do I have? Edit: I am using .Net but I don't mind if somebody shows me platform agnostic version. Solution: Here are a couple of versions of what you're looking for for some common JavaScript toolkits. Mootools - http://digitarald.de/project/fancyupload/ Extjs - http://extjs.com/learn/Extension:UploadForm
undefined
Why does Google prepend while(1); to their JSON responses? Why does Google prepend while(1); to their (private) JSON responses? For example, here's a response while turning a calendar on and off in Google Calendar: while(1);[['u',[['smsSentFlag','false'],['hideInvitations','false'], ['remindOnRespondedEventsOnly','true'], ['hideInvitations_remindOnRespondedEventsOnly','false_true'], ['Calendar ID stripped for privacy','false'],['smsVerifiedFlag','true']]]] I would assume this is to prevent people from doing an eval() on it, but all you'd really have to do is replace the while and then you'd be set. I would assume the eval prevention is to make sure people write safe JSON parsing code. I've seen
undefined
Why does ++[[]][+[]]+[+[]] return the string “10”? This is valid and returns the string "10" in JavaScript (more examples here): ++[[]][+[]]+[+[]] Why? What is happening here? Solution: If we split it up, the mess is equal to: ++[[]][+[]] + [+[]] In JavaScript, it is true that +[] === 0. + converts something into a number, and in this case it will come down to +"" or 0 (see specification details below). Therefore, we can simplify it (++ has precendence over +): ++[[]][0] + [0] Because [[]][0] means: get the first element from [[]], it is true that: [[]][0] returns the inner