In my code below I am trying to create a load more button using AJAX. I have main.php which includes PHP code for calling blogs from database initially, some jQuery code and a load more button. Then I have ajax_more.php which calls more data from database when load more is clicked. Load more buttons are displayed perfectly and when clicked they change to loading and then disappear. Nothing else happens and main.php still shows those two initial blogs which we call first. Please look into code and help where this code has gone wrong.
main.php
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(document).on('click', '.show_more', function () {
var ID = $(this).attr('id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type: 'POST',
url: 'ajax_more.php',
data: 'id=' + ID,
success: function (html) {
$('#show_more_main' + ID).remove();
$('.columns').append(html);
}
});
});
});
</script>
<?php
$query = "
SELECT blogs_id, title, body, posted_by, full_name, bio, posted, category
FROM blogs
INNER JOIN categories
ON categories.category_id=blogs.category_id
WHERE category='cat1' OR category='catt2' OR category='cat3' OR category='cat4'
ORDER BY blogs_id desc
LIMIT 2
";
$result = mysqli_query($con,$query);
$rowCount = mysqli_num_rows($result);
if($rowCount > 0){
while ($row = mysqli_fetch_assoc($result)) {
$blogs_id = $row['blogs_id'];
$title = $row['title'];
$body = $row['body'];
$posted_by = $row['posted_by'];
$full_name = $row['full_name'];
$bio = $row['bio'];
$posted = $row['posted'];
echo "
<div class='db'>
<h2>$title</h2>
<p>$body</p>
<p>$bio</p>
</div>
";
?>
<div class="show_more_main" id="show_more_main<?php echo $blogs_id; ?>">
<span id="<?php echo $blogs_id; ?>" class="show_more" title="Load more posts">Show more</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading…</span></span>
</div>
ajax_more.php
<?php
if(isset($_POST["blogs_id"]) && !empty($_POST["blogs_id"])) {
$query = "
SELECT blogs_id, title, body, posted_by, full_name, bio, posted, category
FROM blogs
INNER JOIN categories ON categories.category_id=blogs.category_id
WHERE category='Entertainment' OR category='Politics' OR category='Sports' OR category='Travel'
AND blogs_id < ".$_POST['blogs_id']."
ORDER BY blogs_id DESC
LIMIT 2
";
$result = mysqli_query($con,$query);
$rowCount = mysqli_num_rows($result);
if($rowCount > 0){
while ($row = mysqli_fetch_assoc($result)) {
$blogs_id = $row['blogs_id'];
$title = $row['title'];
$body = $row['body'];
$posted_by = $row['posted_by'];
$full_name = $row['full_name'];
$bio = $row['bio'];
$posted = $row['posted'];
echo "
<div class='db'>
<h2>$title</h2>
<p>$body</p>
<p>$bio</p>
</div>
";
?>
You should change your query to this
$query = "SELECT blogs_id, title, body, posted_by, full_name, bio, posted, category FROM
blogs INNER JOIN categories ON categories.category_id=blogs.category_id WHERE
(category='Entertainment' OR category='Politics' OR category='Sports' OR category='Travel')
AND blogs_id < " . $_POST['blogs_id'] . " ORDER BY blogs_id DESC LIMIT 2";
All the OR's must be enclosed in the brackets....
You can follow below technique to load more data with just replacing morebox html.
blog.php
<div class="tutorial_list">
<!-- LOAD YOUR PHP BLOG DATA -->
<div class="loading"><img src="fb-load.gif"/></div>
<!-- More Button here $ID values is a last post id value. -->
<div id="show_more<?php echo $ID; ?>" class="morebox">
more
</div>
</div>
<script>
$(document).on('click', '.show_more', function() {
{
var ID = $(this).attr("id");
if (ID) {
$('.morebox').hide();
$('.loding').show();
$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastpost=" + ID,
cache: false,
success: function(html) {
$('.loading').hide();
$('.tutorial_list').append(html);
$("#show_more" + ID).remove(); // removing old more button
}
});
} else {
$(".morebox").html('The End'); // no results
}
return false;
});
</script>
ajax_more.php
<!-- LOAD YOUR PHP BLOG DATA WITH lastpost ID and remember to add below code for load more -->
<!-- More Button here $ID values is a last post id value. -->
<div id="show_more<?php echo $ID; ?>" class="morebox">
more
</div>
Related
I used this ajax PHP code for lazy load and filter according to category, i want to combine both of them because lazy load works on first load but doesnt work with category buttons.
My AJAX code sends limit and start values to fetch.php and fetch data in the division
A 2nd ajax code sends cat_id to load-prod.php to filter data on button click
index.php
<div class="row">
<div class="col-md-12 p-3 text-center">
<span>Categories  </span>
<div class="btn-group" role="group" aria-label="Basic outlined example">
<button type="button" class="btn btn-outline-dark active showct" value="">All</button>
<?php echo show_cat(); ?>
</div>
</div>
<div class="col-md-12">
<div class="row row-cols-1 row-cols-md-3 g-4" id="showpr">
</div>
</div>
<div class="col-md-12 text-center p-3" id="datamsg"></div>
</div>
//lazy load
<script>
var limit = 9; //The number of records to display per request
var start = 0; //The starting pointer of the data
var action = 'inactive'; //Check if current action is going on or not. If not then inactive otherwise active
function lazyload(limit, start)
{
$.ajax({
url:"fetch.php",
method:"POST",
data:{limit:limit, start:start},
cache:false,
success:function(data)
{
$('#showpr').append(data);
if(data == '')
{
$('#datamsg').html("<button type='button' class='btn btn-dark' disabled>No more data</button>");
action = 'active';
}
else
{
$('#datamsg').html("<button type='button' class='btn btn-outline-dark' disabled>Loading More...</button>");
action = 'inactive';
} }});}
if(action == 'inactive')
{
action = 'active';
lazyload(limit, start);
}
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 100 && action== "inactive")
{
action = 'active';
start = start + limit;
setTimeout(function(){
lazyload(limit, start);
}, 1000);}});
</script>
//show according to category
<script>
$(document).ready(function(){
$('.showct').click(function(){
var cat_id = $(this).val();
$.ajax({
url:"load-prod.php",
method:"POST",
data:{cat_id:cat_id},
success:function(data){
$("#showpr").html(data);
}});
});});
</script>
load-prod.php
<?php
include ('connect.php');
global $con;
if(isset($_POST["cat_id"]))
{
if($_POST["cat_id"]!='')
{
$cf = "select * from products where c_id = '".$_POST['cat_id']."'";
}
else{
$cf = "select * from products";
}
$filter = mysqli_query($con,$cf);
while ($ctf=mysqli_fetch_array($filter)) {
echo "<div class='col-12'><h5 class='card-title'>".$ctf['name']."</h5>";
}
}
?>
fetch.php
<?php
include ('connect.php');
global $con;
if(isset($_POST["limit"], $_POST["start"]))
{
$query = "SELECT * FROM album ORDER BY id ASC LIMIT ".$_POST["start"].", ".$_POST["limit"]."";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result))
{
echo "<div class='col-12'><h5 class='card-title'>".$row['name']."</h5>" ;
}
}?>
well, i've an like/unlike script.
When i click on like or unlike, the php request is executed twice.
I've tried several things but i don't understand why.
Here my php request.
$query = "SELECT * FROM like_unlike WHERE postid=".$postid." and userid=".$userid;
$req = $bdd->prepare($query);
$req->execute();
$array = $req->fetchALL();
$count = count($array);
if($count == 0){
$insertquery = "INSERT INTO like_unlike(userid,postid,type)
values(".$userid.",".$postid.",".$type.")";
$insertquery = $bdd->prepare($insertquery);
$insertquery->execute();
and here my js file
$(document).ready(function(){
// like and unlike click
$(".like, .unlike").click(function(){
var id = this.id; // Getting Button id
var split_id = id.split("_");
var text = split_id[0];
var postid = split_id[1]; // postid
// Finding click type
var type = 0;
if(text == "like"){
type = 1;
}else{
type = 0;
}
// AJAX Request
$.ajax({
url: 'likeunlike.php',
type: 'post',
data: {postid:postid,type:type},
dataType: 'json',
success: function(data){
var likes = data['likes'];
var unlikes = data['unlikes'];
var difflikes = data['likes'] - data['unlikes'];
$("#likes_"+postid).text(likes); // setting likes
$("#unlikes_"+postid).text(unlikes);
$("#difflikes_"+postid).text(difflikes); // setting unlikes
}
});
});
HTML:
<img src="<?= $chemin ?>img/up.png" value="Like" id="<?php echo $id_vote_like; ?>"
class="img_vote_up zoom <?= $class_vote_like ?> " style="" /> <?= $log_e ?>
<span id="difflikes_<?php echo $postid; ?>" class="nb_votes"><?php echo $likes_d; ?>
</span>
<?= $log_i ?>
<img src="<?= $chemin ?>img/down.png" value="Unlike" id="<?php echo
$id_vote_unlike; ?>" class="<?= $class_vote_unlike ?> img_vote_down zoom" style=""
/> <?= $log_e ?>
Anyone has an idea ?
I want to load posts by click, I have two files
index.php with ajax
handler.php.
I'm studying AJAX. I understand this technology so by clicking on the button an Ajax request should occur, then the handler returns the data to the Ajax request, and the Ajax query outputs this data. But I can not do it, why? How to fix the error? My error is that the posts are not loaded. The console is empty. I set the echo to the top of the handler, but it did not work. I guess the problem with ajax
index.php with ajax
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
</head>
<body>
<main>
<!-- <article class="news">
<div class="picture"><img src="1news.jpg" width="300" height="300"></div>
<div class="aboutpost">
<h2 class="aboutpost-title">Пожар в торговом центре в Кемерово</h2>
<p class="aboutpost-description">Холдинг, куда входило ЧОП "Зимней вишни", прекратил работу после трагедии</p>
</div>
</article> -->
<?php
require 'infofordb.php';
$link = mysqli_connect($host, $user, $password, $database) or die("Ошибка " . mysqli_error($link));
$query ="SELECT * FROM news ORDER BY id DESC LIMIT 5";
$result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
$articles = array();
while($row = mysqli_fetch_assoc($result)) {$articles[] = $row;}
foreach($articles as $article) {echo '
<article class="news">
<div class="picture">
<img src="/image/'.$article[path].'">
</div>
<div class="aboutpost">
<h2 class="aboutpost-title">'.$article[title].'</h2>
<p class="aboutpost-description">'.$article[description].'</p>
</div>
</article>';}
?>
<center><button id="load">Загрузить ещё</button></center>
<script>
$(document).ready(function(){
var inProgress = false;
var start = 5;
$('#load').click(function() {
$.ajax({
url: 'handler.php',
method: 'POST',
data: {"start" : start},
dataType: 'json',
beforeSend: function() {inProgress = true;}
}).done(function(data){
data = jQuery.parseJSON(data);
alert('nen');
if (data.length > 0) {
//надо вывести
$.each(data, function(index, data){
$('main').append(
'<article class="news"><div class="picture"><img src="/image/' + data.path +
+ '"></div><div class="aboutpost"><h2 class="aboutpost-title">' + data.title +
+ '</h2><p class="aboutpost-description">' + data.description +
+ '</p></div></article>');
});
inProgress = false;
start += 5;
}
});
});
});
</script>
</main>
</body>
</html>
handler.php
<?php
include(infofordb.php);
$start = $_POST['start'];
$link = mysqli_connect($host, $user, $password, $database) or die("Ошибка " . mysqli_error($link));
$query ="SELECT * FROM news ORDER BY id DESC LIMIT {$start}, 5";
$result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
$articles = array();
while($row = mysqli_fetch_assoc($result)) {$articles[] = $row;}
echo json_encode($articles);
?>
dataType: 'json', tells jQuery to parse the returned JSON data. In your code, you call JSON.parse which attempts to parse it again, remove that line(this line I mean data = jQuery.parseJSON(data);).
You need to check your mysql Query in handler.php
$query ="SELECT * FROM news ORDER BY id DESC LIMIT {$start}, 5";
The curly braces does not work in query. May be this solve your problem.
I'm having trouble passing a variable in my a php file to another php file using jquery ajax. I don't know why it doesn't read it though because everytime I echo the variable it's undefined or just plain blank.
teams.php
<?php
// Display members from database
$connect = mysqli_connect('localhost', 'root', '', 'chansandbox');
if(isset($_POST['display'])){
$team = "SELECT * FROM team";
$resultTeam = mysqli_query($connect, $team);
?>
<ul class="teams">
<li><a id="teamheader">LIST OF TEAMS</a></li>
</ul>
<?php
while($arrayTeam = mysqli_fetch_array($resultTeam)){
$team_id = $arrayTeam['team_id'];
?>
<ul class="teams" name="teamId" value="<?php echo $team_id ?>">
<li><?php echo $arrayTeam['team_name']; ?>
<ul class="menu">
<li class="memberdivholder">
<div class="gradeview">
<h1 id='options'><i class="fa fa-cog"></i>
Options:
<button class="topbutton">Grade Team</button>
<button class="topbutton">View Team</button>
<button class="teamdelete">Delete Team</button>
</h1>
</div>
<?php
$member = "SELECT * FROM employee WHERE team_team_id = '$team_id' ORDER BY position_pos_id=17 desc";
$resultMember = mysqli_query($connect, $member);
while($arrayMember = mysqli_fetch_array($resultMember)){
?>
<div class="memberholder">
<h1 class="clearfix">
<?php
if($arrayMember['position_pos_id']==17){
echo "<i class='fa fa-star-o' aria-hidden='true'></i>";
}
?>
<?php echo $arrayMember['emp_fname'] . " " . $arrayMember['emp_lname']; ?>
<button class="viewprofile">View Profile</button>
</h1>
</div>
<?php
}
?>
</li>
</ul>
</li>
</ul>
<?php
}
exit();
mysqli_close($connect);
}
?>
script.js
$('.teams').on('click', '.teamdelete', function(){
var teamId = $(.teams).attr("value");
if(confirm("Are you sure?")){
$.ajax({
url: "http://localhost:81/chansandbox/wp-content/themes/Skeleton/teamdelete.php",
method: "POST",
type: "POST",
data: {
team_id: teamId
},
success: function(data)
{
alert(data);
eval(data);
}
});
}
});
teamdelete.php
<?php
$connect = mysqli_connect('localhost', 'root', '', 'chansandbox');
$team_id = $_POST['teamId'];
$update = "UPDATE employee SET team_team_id = NULL WHERE team_team_id = '$team_id'";
if(mysqli_query($connect, $update)){
echo "Employees Updated";
$deleteteam = "DELETE FROM team WHERE team_id = '$team_id'";
if(mysqli_query($connect, $deleteteam)){
echo "Team deleted '$team_id'";
}
else{
echo "Team not deleted";
}
}
else{
echo "Employees not updated";
}
mysqli_close($connect);
?>
As you can see I'm trying to get the value of the ul (class=teams) in the teams.php and passing it on to the js script file using ajax and var teamId = $(this).attr("value"); and passing it onto teamdelete.php but it doesn't seem to work. Any help would really be appreciated thank you.
because $('.teamdelete') has no attr value ..
in your html you should put
<button class="teamdelete" value="<?php echo $arrayTeam['team_id']; ?>">Delete Team</button>
and in your javascript do this
var teamId = $(this).attr("value");
and in your php .. since the name of the post data = team_id you should do
$team_id = $_POST['team_id'];
Your data variable is incorrect...
The ajax data is sent as data: { NAME : VALUE }. The PHP is essentially calling $_POST['VALUE'] So the php doesn't know what that value is.
The PHP calls:
$_POST['teamId'];
But the ajax sends
team_id:
Try changing the PHP on teamdelete.php to:
$team_id = $_POST['team_id'];
There are additional issues as well...
html:
<button class="teamdelete" value="<?php echo $arrayTeam['team_id']; ?>" >Delete Team</button>
js:
$('.teams').on('click', '.teamdelete', function(){
var teamId = $(this).attr("value"); // ------------ CHANGED
console.log(teamId); // ----------- CHANGED should show the right ID in console
if(confirm("Are you sure?")){
$.ajax({
url: ".....teamdelete.php",
method: "POST",
type: "POST",
data: {
team_id: teamId
},
success: function(data)
{
alert(data);
eval(data);
}
});
}
});
PHP:
<?php
$connect = mysqli_connect('localhost', 'root', '', 'chansandbox');
$team_id = $_POST['team_id']; // ----------- CHANGED
$update = "UPDATE employee SET team_team_id = NULL WHERE team_team_id = '$team_id'";
if(mysqli_query($connect, $update)){
echo "Employees Updated";
$deleteteam = "DELETE FROM team WHERE team_id = '$team_id'";
if(mysqli_query($connect, $deleteteam)){
echo "Team deleted '$team_id'";
}
else{
echo "Team not deleted";
}
}
else{
echo "Employees not updated";
}
mysqli_close($connect);
?>
You can use the developers panel and inspector to confirm that the delete button has the correct value for the team.
I have a mySQL database that is queried and displayed in tables in index.php. I have a file called up.php that handles a click on an < a > in each table that is output from the query in index.php. I need to have a variable that I can extract from a field in each seperate row that is queried, so that when the < a > is clicked it passes the variable to the up.php file to be manipulated. Right now the variable is just being over written and is equal to the value of the last row queried and the database is updated frequently, so I can't just set one to each row, it has to be dynamic.
Here is the index.php file
<?php
$sql = mysql_query("SELECT * FROM blogData ORDER BY id DESC");
//query for even numbered rows where mes_id = even
$sql2=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 0 ORDER BY mes_id DESC");
//query for odd numbered rows where mes_id = even
$sql3=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 1 ORDER BY mes_id DESC");
while(($row = mysql_fetch_array($sql))AND($row2 = mysql_fetch_array($sql2))AND($row3 = mysql_fetch_array($sql3)) ){
$id = $row['id'];
$title = $row['title'];
$content = $row['content'];
$category = $row['category'];
$podcast = $row['podcast'];
$datetime = $row['datetime'];
$message1=$row2['msg'];
//******* this is the variable from the query that needs to be held and not overwritten ********
$mes_id1=$row2['mes_id'];
$totalvotes1=$row2['totalvotes'];
$message2=$row3['msg'];
//******* this is the second variable from the query that needs to also be held and not overwritten *******
$mes_id2=$row3['mes_id'];
$totalvotes2=$row3['totalvotes'];
//attempting to implement this array...? not sure how to use it correctly...
$valuess[]=$row2['mes_id'];
//******* I was trying to use these session variables in up.php but they were being overwritten in the query ********
$_SESSION['message1'] = $row2['msg'];
$_SESSION['message2'] = $row3['msg'];
$_SESSION['mes_id1'] = $row2['mes_id'];
$_SESSION['mes_id2'] = $row3['mes_id'];
$_SESSION['totalvotes1'] = $row2['totalvotes'];
$_SESSION['totalvotes2'] = $row3['totalvotes'];
$_SESSION['valuess'] = $valuess[1];
?>
<?php
// variable used to display file name of $podcast without the extension
$noext = $podcast;
$echodub = rawurlencode($podcast);
// code to display $noext without the file extension
$info = pathinfo($noext);
$noext_name = basename($noext,'.'.$info['extension']);
?>
<!-- ********* echo php variables in html format, in a table with the class of "podcast" -->
<table class="podcast" border="1">
<tr>
<td class="title">
<?php echo $title; ?>
</td>
<td class="timeandcategory">
<?php echo $datetime; ?> <br>
<?php echo $category; ?>
<?php echo $_SESSION['mes_id1']; ?>
<?php echo $_SESSION['mes_id2']; ?>
<?php echo session_id(); ?>
</td>
</tr>
<tr>
<td class="content">
<?php echo $content; ?>
</td>
<td class="myfblike">
<span class='st_fblike_large' displayText='Facebook Like'></span><br>
<span class='st_facebook_large' displayText='Facebook'></span><br>
<span class='st_twitterfollow_large' displayText='Twitter Follow'></span><br>
<span class='st_pinterest_large' displayText='Pinterest'></span><br>
<span class='st_email_large' displayText='Email'></span><br>
<span class='st_sharethis_large' displayText='ShareThis'></span><br>
</td>
</tr>
<tr>
<td class="audio">
<!--echo the audio file -->
<ul class="playlist">
<li><?php echo"$noext_name"; ?></li>
</ul>
</td>
<td>
<!-- ********** this is the cell in the table where the veriables need to be held and sent to up.php ******** -->
<div id="main">
<div id="left">
<span class='up'><img src="up.png" alt="Down" /></span><br />
<?php echo $_SESSION['totalvotes1'] ?><br />
</div>
<div id="message">
<?php echo $_SESSION['message1'] ?>
</div>
<div class="clearfix"></div>
</div>
//********the down.php file is the same as the up.php file... just with opposite variables... im not concerned with this yet until i get the variables to display correctly in up.php
<div id="main">
<div id="left">
<br />
<?php echo $_SESSION['totalvotes2'] ?><br />
<span class='down'><img src="down.png" alt="Down" /></span>
</div>
<div id="message">
<?php echo $_SESSION['message2'] ?>
</div>
<div class="clearfix"></div>
</div>
</td>
</tr>
</table>
<br>
<?php
}
?>
and here is the up.php file
up.php
<?php
session_start();
include("config.php");
$message1 = $_SESSION['message1'];
$message2 = $_SESSION['message2'];
$mes_id1 = $_SESSION['mes_id1'];
$mes_id2 = $_SESSION['mes_id2'];
$totalvotes1 = $_SESSION['totalvotes1'];
$totalvotes2 = $_SESSION['totalvotes2'];
$ip=$_SERVER['REMOTE_ADDR'];
$ip_sql=mysql_query("select ip_add from Voting_IP where mes_id_fk='$mes_id1' and ip_add='$ip'");
$count=mysql_num_rows($ip_sql);
$ip_sql2=mysql_query("select ip_add from Voting_IP where mes_id_fk='$mes_id2' and ip_add='$ip'");
$count2=mysql_num_rows($ip_sql2);
//********* testing if these variables are being passed.....
echo $mes_id1;
echo $mes_id2;
$valuess[0] = $_SESSION['valuess'];
echo $valuess[0];
//********
// if the user has already voted, execute script
if($count==0 && $count2!=0)
{
$sql = "update Messages set totalvotes=totalvotes+1 where mes_id='$mes_id1'";
mysql_query( $sql);
$sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$mes_id1','$ip')";
mysql_query( $sql_in);
$sql = "update Messages set totalvotes=totalvotes-1 where mes_id='$mes_id2'";
mysql_query( $sql);
$sql_in = "DELETE FROM Voting_IP WHERE mes_id_fk='$mes_id2'";
mysql_query( $sql_in);
// if the user has not voted, execute script
}
else if($count==0 && count2==0)
{
$sql = "update Messages set totalvotes=totalvotes+1 where mes_id='$mes_id1'";
mysql_query( $sql);
$sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$mes_id1','$ip')";
mysql_query( $sql_in);
echo $mes_id1;
echo $mes_id2;
}
?>
Thank you so much to anybody who is able to help me!
$(".vote").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(200).html('');
$.ajax({
type: "POST",
url: "up.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
} });
}
else
{
$(this).fadeIn(200).html('');
$.ajax({
type: "POST",
url: "down.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
});
});
With the javascript, I can see what you need to do in order to get it working how you want.
Instead of putting the key1=value1 etc attached to the href, put it in its own attribute called data-options, without the ? pre-pending it. So looking like:
Up/Down
From there, you would modify the JS to be:
$(".vote").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var eData = $(this).attr("data-options");
var dataString = 'id='+ id + '&' + eData ;
var parent = $(this);
From there, you would access them in the up.php and down.php files by using $_POST['key1'], and only need to echo out what your JS is expecting in return from its AJAX call. ^^