<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>

CC BY-SA 3.0
2015-03-24T12:04:16.943Z
I have {{ getCsrfInput() }} in my form and removed data[window.csrfTokenName] = window.csrfTokenValue;. 

Still the same 400 error.
Johannes Lamers
CC BY-SA 3.0
2015-03-24T15:02:34.397Z
@JohannesLamers Updated my answer based on the error details.
Brandon Kelly
CC BY-SA 3.0
2015-03-24T15:16:40.570Z
Still the same error.
Johannes Lamers
CC BY-SA 3.0
2015-03-24T15:19:14.163Z
@JohannesLamers Same error details too? Try deleting your log files first to be sure.
Brandon Kelly
CC BY-SA 3.0
2015-03-24T15:42:50.677Z
Please update your question if the code has changed. Including your template code would help as well.
Brandon Kelly
CC BY-SA 3.0
2015-03-24T17:04:41.497Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/22244/discussion-between-johannes-lamers-and-brandon-kelly).
Johannes Lamers
CC BY-SA 3.0
2015-03-24T11:58:34.040Z
2015-03-24T12:43:22.283Z
2015-03-24T12:43:22.283Z
Brandon Kelly
<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>

CC BY-SA 3.0
2016-03-21T13:56:17.473Z
2016-03-22T12:09:01.897Z
2016-03-22T12:09:01.897Z
Rich Holt
<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>

CC BY-SA 3.0
2015-03-24T12:18:13.447Z
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.
Brandon Kelly
CC BY-SA 3.0
2015-03-24T14:53:32.810Z
@BrandonKelly can you have a look?
Johannes Lamers
CC BY-SA 3.0
2015-05-18T18:20:19.750Z
Does anyone have an update on this one?
Marnix Harderwijk
<form><ajax><frontend><profile>
Change profile in frontend with ajax
# 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:

{{ getCsrfInput() }}




    

        
            

            Ontvang updates over leuke nieuwe producten
            
                
                
            

            
        
        
            

            Ontvang email updates over geinteresseerde kopers
            
                
                
            

            
        
        
            

            Ontvang wekelijks een upate over de producten van jou favoriete verkopers
            
                
                
            

            
        

        
            

            Ontvang email updates van de reacties van jou producten
            
                
                
            

            
        

    
 

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**: @BrandonKelly 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(). 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**: @JohannesLamers Updated my answer based on the error details.  
> **username_0**: Still the same error.  
> **username_1**: @JohannesLamers 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-johannes-lamers-and-brandon-kelly).  

---

### 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..


---

