jquery - Unable to pass data to php using ajax -
first echo images set id php function. im tyring id value jquery click function , pass php function, unfortunately undefined index error. can reason in xampp config or else? becasuse code seems "right".
jquery
$(function postimgid() { $('img').click(function() { var imgid = $(this).attr('id'); $.post('functions.php', {postid:imgid}, function(data) { $('#content').html(data); console.log(imgid); }); }); });
php
function showplayer() { $number =''; $number = $_post['postid']; if(isset($_post['postid'])) { echo "<h2>"; echo $_post['postid']; echo "</h2>"; } }
try:
put in click function:
var imgid = $(this).attr('id'); $.ajax({ type: "get", url: "functions.php", data: 'playerid=' + imgid, success: function(data){ $('#content').html(data); } });
now check isset($_get['playerid'])
, on in php:
if(isset($_get['playerid'])) { echo "<h2>"; echo $_get['playerid']; echo "</h2>"; }
this playerid should not important in database unique ai id.
whole thing works post see: http://api.jquery.com/jquery.post/
Comments
Post a Comment