I understand JSON, but not JSONP. Wikipedia’s document on JSON is (was) the top search result for JSONP. It says this: JSONP or “JSON with padding” is a JSON extension wherein a prefix is specified as an input argument of the call itself. Huh? What call? That doesn’t make any sense to me. JSON is a data format. There’s no
Tag: javascript
How can I encrypt JavaScript code so that it’s not decryptable?
I have some JavaScript code I need to encrypt, but I want to be sure no one can decrypt it. What tools can I use to do this? — Edit — I still want to run the code on my site, I just want to make sure no one else can decrypt the code. Answer The Javascript code is executed
Non-AJAX jQuery POST request
I am trying to use the jQuery POST function but it is handling the request in AJAX style. I mean it’s not actually going to the page I am telling it to go. This function should go to comments.php page with the aid value in hand. It’s posting fine but not redirecting to comments.php. @Doug Neiner Clarification: I have 15
Validate image type using javascript
i have a form like this: Please how can I valid this form using javascript so that only jpg files are uploaded. thanks for reading. Answer You can bind the onsubmit event of your form, and check if the value of your file input ends with “.jpg” or “.jpeg”, something like this: Check the above example here.
How to get the number of lines in a textarea?
What I would like is to count the number of lines in a textarea, e.g: should count up to 4 lines. Basically pressing enter once would transfer you to the next line The following code isn’t working: It always gives ‘1’ no matter how many lines. Answer I have implemented the lines and lineCount methods as String prototypes: Apparently the
How to store objects in HTML5 localStorage/sessionStorage
I’d like to store a JavaScript object in HTML5 localStorage, but my object is apparently being converted to a string. I can store and retrieve primitive JavaScript types and arrays using localStorage, but objects don’t seem to work. Should they? Here’s my code: The console output is It looks to me like the setItem method is converting the input to
How to set DOM element as first child?
I have an element E and I’m appending some elements to it. All of a sudden, I find out that the next element to append should be the first child of E. What’s the trick, how to do it? Method unshift doesn’t work because E is an object, not array. Long way would be to iterate through E’s children and
How to remove element from an array in JavaScript?
Remove the first element I want to remove the first element of the array so that it becomes: Remove the second element To extend this question, what if I want to remove the second element of the array so that it becomes: Answer For a more flexible solution, use the splice() function. It allows you to remove any item in
Replace spaces with dashes and make all letters lower-case
I need to reformat a string using jQuery or vanilla JavaScript Let’s say we have “Sonic Free Games”. I want to convert it to “sonic-free-games”. So whitespaces should be replaced by dashes and all letters converted to small letters. Any help on this please? Answer Just use the String replace and toLowerCase methods, for example: Notice the g flag on
JavaScript alert box with timer
I want to display the alert box but for a certain interval. Is it possible in JavaScript? Answer If you want an alert to appear after a certain about time, you can use this code: If you want an alert to appear and disappear after a specified interval has passed, then you’re out of luck. When an alert has fired,