Not sure if this is an XID issue or what, but occasionally it will be successful but 99% of time it fails. I want someone to seamlessly turn on "vacation mode" by just checking radio button without submit button or refresh... it goes and just sets a variable in database and spits out "success or fail".

I'm using same custom ajax code throughout site and it works except this one page. I'm sending a hidden XID, and tried stripping it down as much as possible.

Error it spits out for me (which i have no clue what that means):

{!-- ra:000000007029234a0000000076a13fa1 --}

Here's my form basically:

<form name="vacationModeForm" class="clearfix vacationModeForm" id="vacationModeForm" action="{site_url}ajax/set_vacation_mode" method="POST" data-postback='vacationPostback' >    

<input type="radio" name="wk{embed:selectedWeek}_Active" value="0" onchange="$('.vacationModeForm').submit();" {if wk{embed:selectedWeek}_Active == 0} checked='checked' {/if} > OF<input type="radio" name="wk{embed:selectedWeek}_Active" value="1" onchange="$('.vacationModeForm').submit();" {if wk{embed:selectedWeek}_Active == 1} checked='checked' {/if} > ON
<input type="hidden" name="XID" value="{XID_HASH}" />

Here is the simple ajax template setting a variable (I've stripped down as much as i could and even hardcoded)

        'wk2_Active'  => '1'
        'member_id' => '1618'

if ( (ee()->db->affected_rows()) > 0) {
    echo 'Success...';
else {
    echo "Failed";

Here's the custom ajax call used throughout. it gets to the ajax template fine (I removed all the other classes for the .on, as I'm using this on every form throughout site and it works great on at least 10 diff. ajax calls/forms

$('body').on("submit", ".vacationModeForm", function(e){
    var form = $(this);
    var postback = form.attr('data-postback');
    // only submit filled in fields so you don't get php undefined
    var fields = $(this).find(":input").filter(function () {
        return $.trim(this.value).length > 0;
    console.log('ajax form submitting to: '+form.attr('action'));
        beforeSend: function() {
            $('.'+postback+'').show().html('<span class="fa fa-spinner fa-pulse fa-3x fa-fw"></span>');
        success: function(response){ 
        error: function(xhr, status, error) {
  • I'm not seeing any jQuery or vanialla JavaScript ajax calls in your code, just a regular POST...
    – jrothafer
    Commented Aug 10, 2015 at 18:23
  • sorry, i updated my question with the custom ajax code. it never "alerts" on error so not sure if that is set up right. it gets to the ajax template fine
    – Chief
    Commented Aug 10, 2015 at 19:02
  • It seems that if I hardcode the db variable 'wk2_Active' to the opposite of what is set (1 or 0), and refresh page it works ONCE. If you keep clicking on the 2 radio buttons to toggle it and keep setting that variable though, it doesn't work again unless i Manually change the db variable to opposite of what my script has.
    – Chief
    Commented Aug 10, 2015 at 19:11


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.