UP or DOWN Voting in Real-Time jQuery Ajax PHP

前端 未结 1 1109
旧巷少年郎
旧巷少年郎 2021-01-22 21:49

Alright, here\'s a quick explanation of what I am doing: I have a website where people can vote UP or DOWN to a \"champion.\" These champions start with 100 health. If you were

相关标签:
1条回答
  • 2021-01-22 22:25

    All of this is just database queries that are returned with JSON. Maybe have two actions on the backend - vote and refresh.

    In the vote method, first check to see the voter's current count. If there are votes left, have the champion's score go up or down.

    Then, return this array:

    1. List item
    2. Champions votes
    3. Votes left
    4. Error (if exists)

    In the refresh method (which would poll the backend server every x number of seconds or minutes) return the number of current votes.

    A fairly easy implementation of ajax.

    Hope this helps!


    EDIT: AJAX learning links

    With jQuery, it is super, super easy. Here's how:

    • http://api.jquery.com/jQuery.parseJSON/
    • http://api.jquery.com/jQuery.getJSON/
    • http://php.net/manual/en/function.json-encode.php
    • Official website: http://www.json.org/
    • http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)
    0 讨论(0)
提交回复
热议问题