1

I have an RSVP box on my website where I want people to click the tick or cross image depending on whether they are coming or not. I currently have a PHP system that updates a SQL database but it reloads the page.

I have tried this code:

$(document).ready(function() {
    var options = {
        url: 'process.php',
        type: 'post',
        data: 'attending',
        success: success
    };

    // bind to the form's submit event
    $('.attending').click(function {
        $(this).ajaxSubmit(options);
        return false;
    });

    function success(responseText, $form) {
        $(".attending").hide();
        $(".success").fadeIn();
    } 
}); 

The RSVP buttons are links with tags But I am strugling with this, any help would be appreciated!

Thanks

5
  • 3
    Check the error console for JS errors. Commented May 3, 2012 at 8:42
  • 1
    You're missing parentheses after the .click function, it should read .click(function() { Commented May 3, 2012 at 8:45
  • What specifically is your issue with the code? When using the code you've posted, is it simply not working and not submitting at all (jquery errors)? Is the page still reloading (meaning your binding isn't working)? Commented May 3, 2012 at 8:45
  • $('.attending').click(function(e) { $(this).ajaxSubmit(options); e.preventDefault(); }); your click event has some syntax error. Commented May 3, 2012 at 8:46
  • Yes, the page keeps reloading and the database is not updating either? Commented May 3, 2012 at 8:46

2 Answers 2

1

The ajaxSubmit function is part of the jquery forms plugin ... are you including that plugin with the page? (You didn't tag the question with jquery-forms-plugin, so I'm guessing no) If this is your first go at jQuery ajax, I'd recommend using the .ajax method first, even though it's more lines of code, to get an understanding of what's going on there.

Sign up to request clarification or add additional context in comments.

2 Comments

I have used your idea and it has worked perfectly, thank you! The only issue is that the img:hover tag doesn't work once the rsvp has been clicked. I can provide a link to the site if you need.
Sure, provide the link and I'll take a look-see.
0

You missed the brackets after declaring the function in your click handler, try this:

// bind to the form's submit event
$('.attending').click(function() {
    $(this).ajaxSubmit(options);
    return false;
});

Or better yet:

// bind to the form's submit event
$('.attending').click(function(e) {
    e.preventDefault();
    $(this).ajaxSubmit(options);
});

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.