Registering jQuery Event Handlers Before the Elements Exist

Update: I removed the link to the article because the site now contains malware. Dave Ward wrote an article Don’t let jQuery’s $(document).ready() slow you down that shows a few situations where execute the contents of a JavaScript file immediately, rather than wrapping it all inside jQuery( document ).ready(). The .live() method has been deprecated since he wrote the […]

Continue reading...

admin-ajax.php Response Fails When Called from Domain Alias

I’m writing a WordPress plugin that uses AJAX and I had everything setup and working fine for awhile. I came back to the code a few hours later and all of the sudden I was getting a failed response, even though the code hadn’t changed. I got the correct JSON response when I loaded the […]

Continue reading...

Cross-Domain AJAX Requests

Browsers prevent standard AJAX calls across domains for security reasons, but you can make JSONP calls instead. If you’re using jQuery you just need to add ‘callback=?’ to the url: $.getJSON('http://some-foreign-server.net/ajax-handler.php?param1=foo&param2=bar&callback=?', function(data) { // do stuff } ); Then setup the request handler to prepend the callback parameter to the response and wrap it in […]

Continue reading...