我完全是新的堆栈溢出和一个合理的新开发,我遇到了我的第一个Ajax函数,不幸的是,虽然我已经阅读了大约20篇文章,但我仍然无法弄清楚需要实现我的功能。一旦我完成了,我可以执行一项功能,我通常可以得到其他任何工作。PHP函数使用on.click和AJAX
我有我建立一个“任务”系统,我有PHP在2个功能,1列出了所有过期的任务,而另一个是删除任务功能,
的任务引导警报列div的优先级和截止日期,在每个警报中,我有2个按钮,1个解雇,2个完成,我有一个函数在PHP中标记任务状态为“2”。
这是我到目前为止。
这是我这完美的作品
<div class='alert alert-danger fade in'>
<strong>Task: </strong><?php echo $row[1];?> <strong class="myAlerts">Note: </strong><?php echo $row[5];?><strong class="myAlerts">Due Date: </strong><?php echo $row[2];?>
<div class='pull-right'>
<button class='close' style='margin-right: 10px;' data-dismiss='alert' aria-label='dismiss'>Completed
<span class='glyphicon glyphicon-ok-circle'></span>
</button>
<button action="removeTask()" class='close' style='margin-right: 10px;' data-dismiss='alert' aria-label='dismiss'>dismiss
<span class='glyphicon glyphicon-remove-circle'></span>
</button>
</div>
</div>
1功能产生什么这是执行任务,它位于函数完成PHP代码/ functions.php中
我的仪表板.PHP调用函数ODTasks()和下面是我需要通过点击结束按钮调用的函数(不留我在模态或页面)
function removeTask($TaskName,$taskID){
if (isset($TaskName)){
echo "Taskname is set";
}
else {
header ('Location: index.php?error="Task completion variables not set [E/1]"');
}
if (isset($TaskID)){
echo "TaskID is set";
}
else {
header ('Location: index.php?error="Task completion variables not set [E/2]"');
}
if (file_exists('../database/mysqli_connection.php')){
require('../database/mysqli_connection.php');
} else {
require('database/mysqli_connection.php');
}
$updateTask = "UPDATE MC_Tasks SET status='2' WHERE TaskName ='".$TaskName."' AND TaskId='".$taskID."'";
$completedTaskResult = mysqli_query($mysqli_connection,$updateTask);
if (mysqli_affected_rows($mysqli_connection) > 0){
echo "task Completed!";
} else {
echo "Task could not be removed, lets check the query on what went wrong";
echo $updateTask;
}
}
这是AJAX
\t <script type="text/javascript">
\t function removeTask() {
$.ajax({
type: "POST",
url: '<?php Thisurl();?>',
data:{action:'removeTask'},
success:function(html) {
alert(html);
}
});
}
\t
\t </script>
这个加到dashboard.php 什么IM测试,但我没有得到任何回音从中:(
<?php
//added for removing a task
if($_POST['action'] == 'removeTask') {
echo "try removing this task";
/* will soon be calling the function with this once the echo works
removeTask($TaskName,$taskID);
*/
}
?>
你的问题是什么?你有什么尝试,什么不工作? – David
你的AJAX在哪里? –
欢迎来到SO。请花几分钟时间[帮助]看看如何提出问题。在这种情况下,我们没有看到任何ajax,并且你没有指定什么不起作用。 – mplungjan