Skip to content

Instantly share code, notes, and snippets.

@elucas
elucas / gist:5056751
Last active December 14, 2015 08:19
This is the Ajax form submission -> content update code that reaffirmed my Man-Crush on Ben.

When you submit the form#filters_form, it requests the response in the background, replaces the existing contents of #article_blocks with the #article_blocks from the response, and updates the url with the params given.

Oh, and if it fails, it redirects you to the form url, so that you're not left in a broken ajax state.

So:

  • No fancy ajax logic server-side
  • No fancy ajax logic client-side
  • Just the bit of content you wanted gets updated

Disclaimer: Tweaks would be needed for POST forms