javascript

How to implement cache for Ajax requests

I have simple application, that shows list of many items, where user can display detail for each item, which is obtained by Ajax. However, if user closes the detail and opens again, application makes another Ajax request, to get the same content again. Is there any simple solution how to prevent this by caching requests on client, so w...

How do I get a web browser to refresh automatically?

Say I want to run a simple Python script that is a web server. And I want to connect a browser to it that refreshes every N seconds, i.e. so the page is updated. How would I do that? I assume the Python server script would generate some HTML that contains javascript that sleeps and forces a refresh? Or can the browser force a refresh? ...

Google Chrome breaks when onfocus sets select size

The following javascript to resize a select list breaks in Google Chrome. It works when tabbing into the field, but clicking on it results in the "Aw, Snap!" error page. <select onfocus="this.setAttribute('size', 3);"> <option>selectList with onfocus</option> <option>2</option> <option>3</option> <option>4</option> </select> Works fin...

Ajax messing up Norwegian characters

I'm trying to take the values from a <textarea> and pass it via XMLHttpRequest to a PHP page that adds the content to a database. However, when it reaches the database, the "å æ ø" characters are converted to "Ã¥ æ Ã". I've searched high and low and tried to change to UTF-8, tried to use JavaScript versions of htmlentities()/htmlsp...

What is the simplest way to add Facebook Connect to a PHP web site?

Facebook Connect I have spent a few weeks putting together a basic web site which uses Facebook connect as authentication. I have studied 'theRunAround', the provided example application. However the code is convoluted and uses a large number of files and classes, most of which have a lot of functionality that I have no need for. I hav...

ajax woes. Submitting without refreshing. I need help.

I'm having problems submitting my ajax form. I am used to the old fashioned way with refresh but this new stuff is beyond me for the time being. It's time to start learning new technolohies. I have an autosuggest box that is getting my results from a database and populating the textbox just fine. When I designed this about 6 months ago,...

Ext.data.Store, Javascript Arrays and Ext.grid.ColumnModel

I am using Ext.data.Store to call a PHP script which returns a JSON response with some metadata about fields that will be used in a query (unique name, table, field, and user-friendly title). I then loop through each of the Ext.data.Record objects, placing the data I need into an array (this_column), push that array onto the end of anoth...

Which web applications serve JSONP?

It'd be interesting to know who serves JSONP. If you know of a site that does (well-known applications are preferred (e.g., GMail, Facebook, Adsense)), please add it as an answer along with a reference. APIs supporting JSONP: Flickr API - Default callback is "jsonFlickrApi", user defined callback is supported. Google Data APIs - User...

jQuery Ajax call - Set variable value on success.

Hey all, I have an application that I am writing that modifies data on a cached object in the server. The modifications are performed through an ajax call that basically updates properties of that object. When the user is done working, I have a basic 'Save Changes' button that allows them to Save the data and flush the cached object. ...

Javascript 'Namespaces' and jQuery AJAX

I'm using the recommendations laid down here (http://www.odetocode.com/articles/473.aspx) to write a JavaScript AJAX webchat system using simulated Namespacing and prototyping. In one of my prototype methods I'm calling the $.ajax method in jQuery. What I then want to do is pass the returned JSON data into a method inside my JavaScript ...

$(d).attr("id") is undefined javascript

I have a variable d that I use like this: $(function() { for(i = 1; i <= 31; i++) { var d = '#days' + i; if ($(d).attr("id").substr(4,2) == 11) { $(d).addClass("date_has_event"); //console.log("diez"); } else { console.log("otro"); } } } However I get th...

How to add/update an attribute to an HTML element using javascript?

I'm trying to find a way that will add / update attribute using javascript. I know I can do it with SetAttribute function but that doesn't work in IE. ...

Really simple question: grabbing the onSubmit event for a form

Hi there, I have a really simple question. I want to know how to grab the onSubmit event from a form to do some form validation, because I don't have access to it directly. (I'm writing a Wordpress plugin for comments, so don't have direct access to the form tag or the submit button.) I've got so frustrated trying to do this for my p...

Why is my submit event not being caught by jQuery in ASP.NET?

I wrote this on a simple ASP.NET page: jQuery(document).ready(function() { jQuery("form").submit(function() { alert("kikoo"); return false }); }); and when I submit (by clicking on a button, link, ...), I never see the alert box. Is there something in asp.net page that "bypass" the submit (I think about the dopostback javasc...

jQuery/JavaScript "this" pointer confusion

The behavior of "this" when function bar is called is baffling me. See the code below. Is there any way to arrange for "this" to be a plain old js object instance when bar is called from a click handler, instead of being the html element? // a class with a method function foo() { this.bar(); // when called here, "this" is the foo...

JSON.stringify() bizarreness

Hello, I'm trying to figure out what's gone wrong with my json serializing, have the current version of my app with and old one and am finding some surprising differences in the way JSON.stringify() works (Using the JSON library from json.org). In the old version of my app: JSON.stringify({"a":[1,2]}) gives me this; "{"a":[1,2]}" ...

ie8 var w= window.open() - "Message: Invalid argument."

I have a site that has an IE8-only problem: The code is: var w = window.open(urlstring, wname, wfeatures, 'false'); The error is: Message: Invalid argument. Line: 419 Char: 5 Code: 0 URI: http://HOSTNAME/js_context.js I have confirmed the line number of the code (the "Line" and "URI" are correct), and I understand in ...

How might I get the script filename from within that script?

I'm pretty sure the answer is no, but thought I'd ask anyway. If my site references a scripted named "whatever.js", is it possible to get "whatever.js" from within that script? Like: var scriptName = ??? if (typeof jQuery !== "function") { throw new Error( "jQuery's script needs to be loaded before " + scriptName + ". C...

Which JavaScript Library Has the Most Comprehensive Class Inheritance Support?

After playing with a dozen different JavaScript Libraries such as Prototype, jQuery, YUI, just to name a few, I found every different library has a different way of simulating some sort of Class Hierarchy and provide some sort of Class Inheritance support. (Other than jQuery) Other than being very annoyed that when you create a new class...

Access Page Model inside of Javascript Block

I have the following jquery code that I've embedded inside of a View: $(document).ready( function() { $(".dblclick").editable("http://localhost/Configuration/Edit", { id: 'nodeID', name: 'nodeValue', event: "dblclick", style: "inherit", submit: "Save", cancel: "Cancel", submitdata : {divison: "1"} ...