以下是我的代码,当我发送data: abuse and remark
时,我获得了成功消息,但alert(uid, vid);
未定义。我的错是什么?我搜索了很多但无法解决它
<script>
$(document).ready(function() {
$('#flag').click(function(){
$( "#dialog" ).dialog({
resizable: false,
height:140,
modal: true,
height: "auto"
});
$('#save').click( function savedata(uid ,vid){
abuse = $('#report_abuse :selected').text();
remark = document.getElementById('motive').value;
var uid = this.uid;
var vid = this.vid;
alert(uid, vid);
$.ajax({
type: "POST",
url: "tpl/main/process.php",
data: { abuse_data : abuse, remark_data : remark },
success: function(data){
alert('successful');
}
});
});
});
});
</script>
<?php if(isset($_SESSION['user_id']))
{
$uid = $_SESSION['user_id'];
$vid = $_SESSION['seen'];
}
?>
<input type="button" name="save" id="save" value="Save" onclick="savedata('$uid', '$vid')"/>
答案 0 :(得分:0)
您已经改进了一个无法按照您希望的方式工作的功能。
顺便说一句,我没有看到函数中使用的uid或vid,但是如果你需要它,那就是你如何使用它:
$(document).ready(function() {
$('#save').on("click",function(e) {
e.preventDefault(); // cancel submit
var abuse = $('#report_abuse :selected').text(),
remark = $('#motive').val(),
uid = $(this).data("uid"),
vid = $(this).data("vid"); // where are they used?
alert("uid:"+uid+" - vid:"+vid);
$.ajax({
type: "POST",
url: "tpl/main/process.php",
data: { abuse_data : abuse, remark_data : remark },
success: function(data){
alert('successful');
}
});
});
});
使用
<?php if(isset($_SESSION['user_id'])) {
$uid = $_SESSION['user_id'];
$vid = $_SESSION['seen'];
} ?>
<input type="button" name="save" id="save" value="Save"
data-uid="<?php echo $uid ?>" data-vid="<?php echo $vid ?>" />
答案 1 :(得分:-1)