Wednesday, 15 January 2014

php - Trying to get data from a button and have a tailored popup with jquery -



php - Trying to get data from a button and have a tailored popup with jquery -

i using modal dialog opener want open when user clicks 1 of few available buttons. buttons have different "artist_id" associated them. when button clicked, have php script should run , set user id , artist id in table keeps track of "liking" relationships. below relevant code:

index.php:

//script <script> $(function() { $( "#dialog-modal" ).dialog({autoopen: false, height: 250, width: 400, modal: true}); $( "#opener" ).click(function() { $( "#dialog-modal" ).dialog( "open" ); $.get('/like_artist.php', {artist_id : $(this).data('artist_id')}) .done(function(data) { alert("data loaded: " + data.artist_id); }); }); }); </script>

//button:

<button type="button" id="opener" data-artist_id="1">play city</button>

//dialog content (i have alter based on button clicked):

<div id="dialog-modal" title="basic dialog"> <p>you have liked ...</p> <p>this default dialog useful displaying information. dialog window can moved, resized , closed 'x' icon.</p> </div>

like_artist.php: takes user id , artist id , puts them in relationship table user_artists

<?php session_start(); require_once "database.php"; db_connect(); require_once "auth.php"; $current_user = current_user(); include_once("config.php"); $artist_id = $_get['artist_id']; $user_id = $current_user['id']; $query = "insert `user_artists` (`artist_id`, `user_id`) values (''$artist_id', '$user_id')"; $result = mysql_query($query); ?>

the alert have set in top script there see if getting right artist_id data-artist_id property, not returning anything.

thank help!

you're not returning (echoing) in like_artist.php, naturally ajax response empty well.

echo json_encode(array('artist_id' => $artist_id));

then you'll have decode on frontend.

php mysql jquery

No comments:

Post a Comment