Help adding ajax to a pod page

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  logikal16 3 years, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #162182

    laura
    Member

    I am trying to build function to vote for a particular essay and I just need a little help figuring out how to incorporate ajax so it updates right on the page. Right now I have a pod page that pulls the current number of votes for each essay and displays it above the essay. There is a form button that when pressed pulls up a php file that adds one to the vote count and displays the new vote count on the update page.

    Can anyone point me in the right direction on how to incorporate ajax to have the result sent back to the original pod page?

    This is my pod page:
    <pre>
    <?php
    $orderby = ‘t.date ASC’;
    $limit = 100;
    $where = ‘t.featured_essay = 1′;
    $featuredEssay = new Pod(‘essay’);
    $featuredEssay->findRecords($orderby,$limit,$where);
    while ($featuredEssay->fetchRecord()) {
    $id = $featuredEssay->get_field(‘id’);
    $title = $featuredEssay->get_field(‘name’);
    $date = $featuredEssay->get_field(‘date’);
    $date = date("m/d/Y",strtotime($date));
    $essay = $featuredEssay->get_field(‘essay’);
    $votes = $featuredEssay->get_field(‘votes’);
    $votes = round($votes);
    ?>

    <?php } ?>;
    </pre>

    and my update page:
    <pre>
    <?php
    if(isset($_POST['vote'])) {
    $id=$_POST['id'];

    ?>
    </pre>

    #162183

    logikal16
    Member

    Laura,

    The best example for getting AJAX working is to look at the code for Pods itself. Look in core/manage_pods.php. For starters, here’s a really good example:

    <pre>
    function dropPage() {
    if (confirm("Do you really want to drop this page?")) {
    jQuery.ajax({
    type: "post",
    url: "<?php echo PODS_URL; ?>/ajax/api.php",
    data: "action=drop_page&id="+page_id,
    success: function(msg) {
    // "msg" is whatever is returned back from the AJAX call
    // Do something here (like update some HTML elements)
    }
    });
    }
    }
    </pre>

    The above function passes 2 variables to the file "api.php": action, and id.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Wordpress Cloud Hosting