hello ive been trying to get the current environment in rails but i think im doing something wrong with my javascript, but i dont seem to know what. in my application.js i have… it always goes into my else statement even if i am in development mode. what am i doing wrong? thank you how to get environmen…
Tag: javascript
Creating an iframe with given HTML dynamically
I’m trying to create an iframe from JavaScript and fill it with arbitrary HTML, like so: I would expect iframe to then contain a valid window and document. However, this isn’t the case: > console.log(iframe.contentWindow); null Try it for yourself: http://jsfiddle.net/TrevorBurnham/9k9Pe/ What …
Stop characters being typed into form
I have this jQuery which stops the enter key from being pressed and I have prepared it to accept an array of disallowed keypresses.. I want to do similar thing with the | character, but since it is shift of 220 and I don’t need to stop from being entered into the form, how do I restrict that character
How to compute the sum and average of elements in an array? [duplicate]
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. This question already has answers here: How to find the sum of an array of numbers (59 answers) Closed 3 months ag…
Javascript JSON comparison/diff?
Say I have the following 2 json objects: Sample Function: function (jsonstringA, jsonstringB) Example (If JSON A and JSON B used as parameters): Returns a new JSON object containing: Note that it is using jsonstringA as the base of the comparison, so the function returns only the fields missing and values of …
String index in a JavaScript array
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://jsfi…
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 p…
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-2…
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 ano…