All Questions

3436
votes
23answers
904828 views

How do I return the response from an asynchronous call?

I have a function foo which makes an Ajax request. How can I return the response from foo? I tried to return the value from the success callback as well as assigning the response to a local variable ...
1988
votes
32answers
240576 views

JavaScript closure inside loops – simple practical example

var funcs = []; for (var i = 0; i < 3; i++) { // let's create 3 functions funcs[i] = function() { // and store them in funcs console.log("My value: " + i); // each should...
1397
votes
19answers
566963 views

Event binding on dynamically created elements?

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off. This happens on page ready...
634
votes
5answers
163911 views

How to access the correct `this` inside a callback?

I have a constructor function which registers an event handler: function MyConstructor(data, transport) { this.data = data; transport.on('data', function () { alert(this.data);...
445
votes
6answers
110336 views

Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

Given the following examples, why is outerScopeVar undefined in all cases? var outerScopeVar; var img = document.createElement('img'); img.onload = function() { outerScopeVar = this.width; }; im...
2706
votes
73answers
2799416 views

How can I get query string values in JavaScript?

Is there a plugin-less way of retrieving query string values via jQuery (or without)? If so, how? If not, is there a plugin which can do so?
7663
votes
88answers
1142057 views

How do JavaScript closures work?

A PHP Error was encountered

Severity: Notice

Message: Undefined index: body

Filename: views/Tagged_view.php

Line Number: 87

Backtrace:

File: /home/admin/web/allinonescript.com/public_html/application/views/Tagged_view.php
Line: 87
Function: _error_handler

File: /home/admin/web/allinonescript.com/public_html/application/controllers/Questions.php
Line: 158
Function: view

File: /home/admin/web/allinonescript.com/public_html/index.php
Line: 297
Function: require_once

535
votes
16answers
289817 views

Access / process (nested) objects, arrays or JSON

I have a (nested) data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)? For example: var data = { code: 42, it...
295
votes
6answers
73713 views

Why does jQuery or a DOM method such as getElementById not find the element?

What are the possible reasons for document.getElementById, $("#id") or any other DOM method / jQuery selector not finding the elements? Example problems include: jQuery silently failing to bind an e...
331
votes
4answers
25999 views

What is the difference between client-side and server-side programming?

I have this code: <script type="text/javascript"> var foo = 'bar'; <?php file_put_contents('foo.txt', ' + foo + '); ?> var baz = <?php echo 42; ?>; aler...

Previous Next