I want to use a specific string in addition to a number to the index of array, I make like this When I print out the tmpArray, it’s empty. Also the size is 0. When I remove the “elem” from the index of the array, it works properly. What should I do? Here’s a real example: http://jsfiddle.net/dfg3x/ Answer JavaScript
Flask url_for URLs in Javascript
What is the recommended way to create dynamic URLs in Javascript files when using flask? In the jinja2 templates and within the python views url_for is used, what is the recommended way to do this in .js files? Since they are not interpreted by the template engine. What basically want to do is: Which is not possible. But naturally, I
How to send data in request body with a GET when using jQuery $.ajax()
The service API I am consuming has a given GET method that requires the data be sent in the body of the request. The data required in the body is a list of id’s separated by hypen and could potentially be very large and thus it must be sent in the body otherwise it will likely foobar somewhere in the
What is the “right” JSON date format?
I’ve seen so many different standards for the JSON date format: Which one is the right one? Or best? Is there any sort of standard on this? Answer JSON itself does not specify how dates should be represented, but JavaScript does. You should use the format emitted by Date’s toJSON method: 2012-04-23T18:25:43.511Z Here’s why: It’s human readable but also succinct
AJAX and user leaving a page
I’m working on a chat and I’m trying to figure out how I can detect that the user has left the page or not. Almost everything is being handled by the database to avoid the front end from messing up. So what I’m trying to do is once the page is left for any reason (window closed, going to another
Custom mouse events in backbonejs
What would be a good way of supporting custom mouse events? For example, I currently have: But instead of mousedown, I would like to create a custom event called mousedrag which would be a combination of mousedown and mousemove. Is there any recommended way of adding such a custom event? Answer Since Backbone element events are simply jQuery ( or
What’s the right mindset in using jQuery’s event.stopPropagation()
I have two approaches in mind on how to apply jQuery’s event.stopPropagation(): Optimistic approach – By default, all event handlers are without stopPropagation(). stopPropagation() would be added to a handler only if there’s some unnecessary and undesired behaviour caused by event bubbling. Pessimistic approach – By default, stopPropagation() is added to all event handlers. If there’s some desired behaviour missing
Get callback in CoffeeScript with library
I am using the YouTube API to embed a video on a page. I call swfobject.embedSWF which embeds the video on the page, it works. When it is done loading, the API is supposed to call onYouTubePlayerReady. My question though is where do I have to place the callback in my class to get the function called? Here is the
How to implement a click event on mutually exclusive checkboxes in jQuery?
I have two checkboxes: I’ve made them mutually exclusive with: This works fine. But I also want to add additional click functionality to the ‘inside’ checkbox. I want it to enable/disable a textarea on the same form, so I’ve done this: So, if the ‘inside’ checkbox is checked, the textarea will be enabled, if it’s not checked, the textarea should
NewLine escape character not working
We know that n is used to feed a new line in JavaScript. How should I use it for an output (in a for-loop): or Neither seems to work. Answer This has nothing to do with JavaScript. In HTML, all whitespace (including newlines) is collapsed and treated as a single space. To do a line break in HTML: Use <br>