ユーザーが使用可能ないくつかのボタンのいずれかをクリックしたときに開きたいモーダル ダイアログ オープナーを使用しています。ボタンにはすべて、異なる「artist_id」が関連付けられています。ボタンがクリックされると、「好み」の関係を追跡するテーブルにユーザー ID とアーティスト ID を実行して配置する PHP スクリプトもあります。以下は関連するコードです。
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 type="button" id="opener" data-artist_id="1">Play My City</button>
//ダイアログの内容 (クリックされたボタンに基づいてこの変更を行いたい):
<div id="dialog-modal" title="Basic dialog">
<p>You have just liked ...</p>
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
like_artist.php: ユーザー ID とアーティスト ID を受け取り、関係テーブル 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 INTO `user_artists`
(`artist_id`, `user_id`)
VALUES
(''$artist_id', '$user_id')";
$result = mysql_query($query);
?>
一番上のスクリプトに入れたアラートは、data-artist_id プロパティから正しい artist_id を取得しているかどうかを確認するためにありますが、何も返されません。
ご協力ありがとうございました!