我正在使用一个模式对话框打开器,当用户单击几个可用按钮之一时,我想打开它。这些按钮都有一个不同的“artist_id”与之关联。单击按钮时,我还有一个 php 脚本应该运行并将用户 ID 和艺术家 ID 放在一个跟踪“喜欢”关系的表中。下面是相关代码:
索引.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 属性中获取了正确的艺术家 ID,但它没有返回任何内容。
感谢您的帮助!