Answers.Body: <p>The 400 error you’re getting is coming from <a href="http://buildwithcraft.com/classreference/controllers/BaseController#requirePostRequest-detail" rel="nofollow">BaseController::requirePostRequest()</a>. It’s happening because this line:</p>
  
  <pre><code>type: "post",
  </code></pre>
  
  <p>should be:</p>
  
  <pre><code>method: "POST",
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T12:04:16.943Z
Answers.Text: I have {{ getCsrfInput() }} in my form and removed data[window.csrfTokenName] = window.csrfTokenValue;. 
  
  Still the same 400 error.
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T15:02:34.397Z
Answers.Text: @JohannesLamers Updated my answer based on the error details.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T15:16:40.570Z
Answers.Text: Still the same error.
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T15:19:14.163Z
Answers.Text: @JohannesLamers Same error details too? Try deleting your log files first to be sure.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T15:42:50.677Z
Answers.Text: Please update your question if the code has changed. Including your template code would help as well.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T17:04:41.497Z
Answers.Text: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/22244/discussion-between-johannes-lamers-and-brandon-kelly).
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T11:58:34.040Z
Answers.LastActivityDate: 2015-03-24T12:43:22.283Z
Answers.LastEditDate: 2015-03-24T12:43:22.283Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <p>This worked for me. Add <code>data: data,</code> before <code>dataType: "json",</code></p>
  
  <p>I had the same error, and still get the same error if data source is not defined..</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-21T13:56:17.473Z
Answers.LastActivityDate: 2016-03-22T12:09:01.897Z
Answers.LastEditDate: 2016-03-22T12:09:01.897Z
Answers.UserDisplayName: Rich Holt
Body: <p>I'm trying to update some checkbox fields through the frontend with ajax.
  After clicking / change of the checkbox the form needs to update the profile. </p>
  
  <p>Template code:</p>
  
  <pre><code>&lt;form class="form-horizontal form-ajax" method="POST" action="" accept-charset="UTF-8" id="notificaties"&gt;
  {{ getCsrfInput() }}
  &lt;input type="hidden" name="action" value="/users/saveUser"&gt;
  &lt;input type="hidden" name="redirect_" value="account"&gt;
  &lt;input type="hidden" name="userId" value="{{ user.id }}"&gt;
  
      &lt;ul class="action-list"&gt;
  
          &lt;li&gt;
              &lt;p&gt;
  
              Ontvang updates over leuke nieuwe producten
              &lt;span class="pull-right"&gt;
                  &lt;input type="hidden" name="fields[emailUpdates]" value="0"&gt;
                  &lt;input class="ajaxcheck" type="checkbox" id="fields_emailUpdates" name="fields[emailUpdates]" value="1" {% if user is defined and user.emailUpdates %} checked="checked"{% endif %}&gt;
              &lt;/span&gt;
  
              &lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;p&gt;
  
              Ontvang email updates over geinteresseerde kopers
              &lt;span class="pull-right"&gt;
                  &lt;input type="hidden" name="fields[emailReactie]" value="0"&gt;
                  &lt;input class="ajaxcheck" type="checkbox" id="fields_emailReactie" name="fields[emailReactie]" value="1" {% if user is defined and user.emailReactie %} checked="checked"{% endif %}&gt;
              &lt;/span&gt;
  
              &lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;p&gt;
  
              Ontvang wekelijks een upate over de producten van jou favoriete verkopers
              &lt;span class="pull-right"&gt;
                  &lt;input type="hidden" name="fields[emailFavorieten]" value="0"&gt;
                  &lt;input class="ajaxcheck" type="checkbox" id="fields_emailFavorieten" name="fields[emailFavorieten]" value="1" {% if user is defined and user.emailFavorieten %} checked="checked"{% endif %}&gt;
              &lt;/span&gt;
  
              &lt;/p&gt;
          &lt;/li&gt;
  
          &lt;li&gt;
              &lt;p&gt;
  
              Ontvang email updates van de reacties van jou producten
              &lt;span class="pull-right"&gt;
                  &lt;input type="hidden" name="fields[emailComments]" value="0"&gt;
                  &lt;input class="ajaxcheck" type="checkbox" id="fields_emailComments" name="fields[emailComments]" value="1" {% if user is defined and user.emailComments %} checked="checked"{% endif %}&gt;
              &lt;/span&gt;
  
              &lt;/p&gt;
          &lt;/li&gt;
  
      &lt;/ul&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>JS code:</p>
  
  <pre><code> $(".ajaxcheck").click(function(){
      var data = $(this).parents('form').serialize()
  
      $.ajax({
          context: this,
          method: "POST",
          dataType: "json",
          url: "/actions/users/saveUser",
          success: function(data, response){
              $(this).parents('.account-item').remove();
              console.log("success", response, data);
          }
      });
  });
  </code></pre>
  
  <p>But it gives me an error: GET <a href="http://shop.craft.dev/actions/users/saveUser" rel="nofollow">http://shop.craft.dev/actions/users/saveUser</a> 400 (Bad Request)</p>
  
  <p>The form gets updated. So it works. But it still gives me this error:</p>
  
  <p>In my craft.log file:</p>
  
  <p>exception.Craft\HttpException.400
  Message exception 'Craft\HttpException' in /Volumes/HDD Drive/Sites/Shop/app/controllers/BaseController.php:191</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-24T12:18:13.447Z
Comments.Text: Enable [Dev Mode](http://buildwithcraft.com/docs/config-settings#devMode) and see if the response body gives you any details. Even if it doesn’t, you should be able to find more info in craft/storage/runtime/logs/craft.log (search for `exception.Craft\HttpException.400`). Please update your question with any additional details on the error.
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-24T14:53:32.810Z
Comments.Text: @BrandonKelly can you have a look?
Comments.UserDisplayName: Johannes Lamers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-18T18:20:19.750Z
Comments.Text: Does anyone have an update on this one?
Comments.UserDisplayName: Marnix Harderwijk
Tags: <form><ajax><frontend><profile>
Title: Change profile in frontend with ajax
ThreadText: # Change profile in frontend with ajax
  
  (Asked by: username_0 on 2015-03-24)
  
  I'm trying to update some checkbox fields through the frontend with ajax.
  After clicking / change of the checkbox the form needs to update the profile.
  
  Template code:
  
  ```
  <form class="form-horizontal form-ajax" method="POST" action="" accept-charset="UTF-8" id="notificaties">
  {{ getCsrfInput() }}
  <input type="hidden" name="action" value="/users/saveUser">
  <input type="hidden" name="redirect_" value="account">
  <input type="hidden" name="userId" value="{{ user.id }}">
  
      <ul class="action-list">
  
          <li>
              <p>
  
              Ontvang updates over leuke nieuwe producten
              <span class="pull-right">
                  <input type="hidden" name="fields[emailUpdates]" value="0">
                  <input class="ajaxcheck" type="checkbox" id="fields_emailUpdates" name="fields[emailUpdates]" value="1" {% if user is defined and user.emailUpdates %} checked="checked"{% endif %}>
              </span>
  
              </p>
          </li>
          <li>
              <p>
  
              Ontvang email updates over geinteresseerde kopers
              <span class="pull-right">
                  <input type="hidden" name="fields[emailReactie]" value="0">
                  <input class="ajaxcheck" type="checkbox" id="fields_emailReactie" name="fields[emailReactie]" value="1" {% if user is defined and user.emailReactie %} checked="checked"{% endif %}>
              </span>
  
              </p>
          </li>
          <li>
              <p>
  
              Ontvang wekelijks een upate over de producten van jou favoriete verkopers
              <span class="pull-right">
                  <input type="hidden" name="fields[emailFavorieten]" value="0">
                  <input class="ajaxcheck" type="checkbox" id="fields_emailFavorieten" name="fields[emailFavorieten]" value="1" {% if user is defined and user.emailFavorieten %} checked="checked"{% endif %}>
              </span>
  
              </p>
          </li>
  
          <li>
              <p>
  
              Ontvang email updates van de reacties van jou producten
              <span class="pull-right">
                  <input type="hidden" name="fields[emailComments]" value="0">
                  <input class="ajaxcheck" type="checkbox" id="fields_emailComments" name="fields[emailComments]" value="1" {% if user is defined and user.emailComments %} checked="checked"{% endif %}>
              </span>
  
              </p>
          </li>
  
      </ul>
   </form>
  
  ```
  
  JS code:
  
  ```
   $(".ajaxcheck").click(function(){
      var data = $(this).parents('form').serialize()
  
      $.ajax({
          context: this,
          method: "POST",
          dataType: "json",
          url: "/actions/users/saveUser",
          success: function(data, response){
              $(this).parents('.account-item').remove();
              console.log("success", response, data);
          }
      });
  });
  
  ```
  
  But it gives me an error: GET <http://shop.craft.dev/actions/users/saveUser> 400 (Bad Request)
  
  The form gets updated. So it works. But it still gives me this error:
  
  In my craft.log file:
  
  exception.Craft\HttpException.400
  Message exception 'Craft\HttpException' in /Volumes/HDD Drive/Sites/Shop/app/controllers/BaseController.php:191
  
  **Tags:** form, ajax, frontend, profile
  
  > **Comments:**
  > **username_1**: Enable [Dev Mode](http://buildwithcraft.com/docs/config-settings#devMode) and see if the response body gives you any details. Even if it doesn’t, you should be able to find more info in craft/storage/runtime/logs/craft.log (search for `exception.Craft\HttpException.400`). Please update your question with any additional details on the error.  
  > **username_0**: @username_1 can you have a look?  
  > **username_2**: Does anyone have an update on this one?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-03-24. Score: 2
  
  The 400 error you’re getting is coming from [BaseController::requirePostRequest()](http://buildwithcraft.com/classreference/controllers/BaseController#requirePostRequest-detail). It’s happening because this line:
  
  ```
  type: "post",
  
  ```
  
  should be:
  
  ```
  method: "POST",
  
  ```
  
  > **Comments:**
  > **username_0**: I have {{ getCsrfInput() }} in my form and removed data[window.csrfTokenName] = window.csrfTokenValue;.   Still the same 400 error.  
  > **username_1**: @username_0 Updated my answer based on the error details.  
  > **username_0**: Still the same error.  
  > **username_1**: @username_0 Same error details too? Try deleting your log files first to be sure.  
  > **username_1**: Please update your question if the code has changed. Including your template code would help as well.  
  > **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/22244/discussion-between-username_0-username_0-and-username_1).  
  
  ---
  
  ### Answer by username_3 on 2016-03-21. Score: -1
  
  This worked for me. Add `data: data,` before `dataType: "json",`
  
  I had the same error, and still get the same error if data source is not defined..
  
  
  ---
  
  