Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $user_id = $_SESSION['user_id'];
- //$polls_id = $_SESSION['polls_id'];
- if($_GET) {
- if(isset($_GET['insert'])) {
- vote_poll1($user_id, $polls_id);
- }
- elseif(isset($_GET['select'])) {
- vote_poll2($user_id, $polls_id);
- }
- }
- function vote_poll1($user_id, $polls_id){
- $postdata = http_build_query(
- array(
- 'user_id' => $user_id,
- 'poll_id' => $polls_id,
- 'vote_value' => '1'
- )
- );
- $opts = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-type: application/x-www-form-urlencoded',
- 'content' => $postdata
- )
- );
- $context = stream_context_create($opts);
- $result = file_get_contents('http://whichis4me.herokuapp.com/api/v1/polls/'. $polls_id . '/castvote', false, $context);
- public function getButtons() {
- //$_SESSION['polls_id'] = $this->polls_id;
- //echo $_SESSION['polls_id'];
- echo $this->polls_id;
- echo '<script src="https://code.jquery.com/jquery-2.0.0.js"></script>';
- echo '<form action="ajax.php" id=' . $this->polls_id . '>';
- echo "t";
- echo '<input type="submit" class="button" name="insert" value="Click here to vote" />';
- echo "tttttt ";
- echo '<input type="submit" class="button" name="select" value="Click here to vote" />';
- echo "</form>";
- echo "<script>";
- echo "$(document).ready(function(){";
- echo "$('.button').click(function(){";
- echo "var clickBtnValue = $(this).val();";
- echo "var idValue = $(this).attr('id')";
- echo "var ajaxurl = 'ajax.php'";
- //echo "var id = " . $this->polls_id;
- echo "data = {'action': clickBtnValue, 'id': idValue};";
- echo "$.post(ajaxurl, data, function (response) {";
- echo 'alert("Action performed successfully");';
- echo "});";
- echo "});";
- echo "});";
- echo "</script>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement