title: django forms and ajax
body: <p>I'm trying to create a page with two functional parts:</p>
  
  <ul>
  <li>a form which the user fills and submits many times</li>
  <li>a chart which updates every time the user submits the form</li>
  </ul>
  
  <p>I'm using <a href="https://docs.djangoproject.com/en/dev/topics/forms/" rel="nofollow">django forms</a> and <a href="http://jquery.com/" rel="nofollow">jQuery</a> and I can't quite figure out how the design fits together.<br>
  Upon submission of the form one of two things should happen, either the chart (and only the chart) updates or, if there is a form validation error, the form section should update with the appropriate error messages. So actually one Ajax call should update either part.<br>
  I'd like only the relevant <code>div</code> to update (either form or chart) instead of the entire page which includes the other <code>div</code>, a logo and other static graphics.<br></p>
  
  <p>One of the challenges is that if the form sumbission went well, I'd like to return a JSON object which updates the chart, as I'm using a 3rd party charting package, however if the submission failes the returned content should be an HTML response with the updated form.</p>
  
  <p>What would be a correct pattern for the django view for this behavior?<br>
  What would be a correct javascript\jQuery pattern for this behavior?<br>
  If this approach is not correct, what would be an alternative approach?</p>