Brett Malone :
What I am trying to do is have "listings" all with unique id's. When a user clicks on a listing (each has anchor tag), I want to query the database with the listing ID, then display the information on the screen. Im not going to worry about echoing the data back to the website, I just want to send the variable at which the database SELECTS for.
Script
$(function(){
$('.tasks-column').on('click', 'a', function(){
var pid = $(this).attr("id");
$.ajax({
method: 'POST',
url: '/php/info-get.php',
data: {pid : $('#pid')}
HTML
<a id="1">Listing></a>
<a id="2">Listing</a>
HTML div I want Data in
<div class="DataGoesHereAfterClick"><?=$title?></div>
PHP
<?php
include 'sqlconnection.php';
$conn = OpenCon();
$stmt = $conn->prepare('SELECT title FROM tasks WHERE pid=?'); $pid = 'pid'; $stmt->bind_param('i', $pid);
$stmt->execute();
$stmt->bind_result($title);
$stmt->fetch();
$stmt->close();
echo json_encode($title);
CloseCon($conn);
?>
Miqueias Francisco :
Script
$(function(){
$(".listing-act").click(function() {
$.ajax({
type: 'POST',
url: '/php/info-get.php',
dataType: 'json',
data: 'pid=' + $(this).attr("id"),
success: function (response) {
$('.DataGoesHereAfterClick').html(response);
}
}
HTML
<a id="1" class="listing-act">Listing></a>
<a id="2" class="listing-act">Listing</a>
PHP
<?php
include 'sqlconnection.php';
$conn = OpenCon();
$stmt = $conn->prepare('SELECT title FROM tasks WHERE pid='.$_POST['pid']);
$stmt->execute();
$stmt->bind_result($title);
$stmt->fetch();
$stmt->close();
echo json_encode($title);
CloseCon($conn);
?>