Skip to content

Instantly share code, notes, and snippets.

@rpheath
Created June 21, 2010 15:44
Show Gist options
  • Select an option

  • Save rpheath/447042 to your computer and use it in GitHub Desktop.

Select an option

Save rpheath/447042 to your computer and use it in GitHub Desktop.
// Why is this not working in IE!?!?
// (using jQuery 1.4.2 and Rails 2.3.5)
// The issue is that it either: 1) posts as a regular form, ignoring the ajax
// or 2) asks me to download a file
// Yes, I've tried config.action_controller.use_accept_header = false
// in environment.rb and that has no effect on the outcome
// force accept headers
$.ajaxSetup({
'beforeSend': function(xhr) {
xhr.setRequestHeader('Accept', 'text/javascript')
}
})
// the plugin
$.fn.submitWithAjax = function() {
this.live('submit', function(e) {
e.preventDefault()
$.post(this.action + ".js", $(this).serialize(), null, "script")
})
}
// initialize ajax forms
$('div.ajax form').submitWithAjax()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment