phpjavascriptjqueryajaxwordpress

Copy Ajax request function, that calls a PHP function, noob stuff


I found a JS-jQuery File what does almost what I need. If you click the checkbox it calls a PHP function. Now I want to add another checkbox which calls another PHP function.

So I tried to copy the function. And change the values but that didn't work.

I'm sure you will see the mistake in 1-2 seconds, so thanks for a short look in the JS-Fiddle!

This part I would like to copy, also see my attempts in the JS-Fiddle

$('input[name="ive-read-this"]').change(function (evt) {
    alert("markiere als gelesen.");
            
    // We can retrieve the ID of this post from the <article>'s ID. 
    // This will be required
    // so that we can mark that the user has read this particular post and 
    // we can hide it.
    var sArticleId, iPostId;
            
    // Get the article ID and split it - the second index is always 
    // the post ID in twentyeleven
    sArticleId = $("article").attr('id');
    iPostId = parseInt(sArticleId.split('-')[1]);

    // Initial the request to mark this this particular post as read
    $.post(ajaxurl, {        
        action:  'mark_as_read',
        post_id: iPostId      
    }

Solution

  • I just forgot to add also this:

    add_action( 'wp_ajax_mark_as_unread', array( &$this, 'mark_as_unread' ) );

    So it's solved! Regards