Javascript 如何在使用模式时使用AJAX在js和php之间进行通信?
我在学习如何成功使用ajax方面遇到了很多困难。在我学习这一点的项目中,我在图表上的各种人之间进行选择。当我选择此人时,我单击他们的按钮并更新数据库。但是,我需要能够填充一个模态,以便向那个人发送消息。我一直在尝试使用ajax来实现这一点,因为我只需要选择一个$userid变量 下面是我的代码,如果有一种不使用ajax的更简单的方法,那也太好了 phpJavascript 如何在使用模式时使用AJAX在js和php之间进行通信?,javascript,php,jquery,ajax,post,Javascript,Php,Jquery,Ajax,Post,我在学习如何成功使用ajax方面遇到了很多困难。在我学习这一点的项目中,我在图表上的各种人之间进行选择。当我选择此人时,我单击他们的按钮并更新数据库。但是,我需要能够填充一个模态,以便向那个人发送消息。我一直在尝试使用ajax来实现这一点,因为我只需要选择一个$userid变量 下面是我的代码,如果有一种不使用ajax的更简单的方法,那也太好了 php <?php if (isset($_POST['usrid'])) { $whatineed = $_POST['usrid'];
<?php if (isset($_POST['usrid'])) {
$whatineed = $_POST['usrid'];
?>
div modal stuff
<?php>
任何帮助都将不胜感激 我没有机会检查代码,但我会尽力给你一个完整的画面: update.php:
<?php
if (isset($_POST['usrid'])) {
$whatineed = "The updater have an user ID " . $_POST['usrid'];
} else {
$whatineed = "The updater have nothing to do, because an user ID have not been received.";
}
echo($whatineed);// this is the message TO modal
?>
再说一次,这只是一个问题。必须在整个代码中对这些部分进行调整和调试。是模态弹出窗口吗?解释
填充模态以便向此人发送消息。在ajax回调中运行的代码只能在当前页面上运行。它是一个模式弹出窗口(来自引导),允许您向其他用户发送消息
<?php
if (isset($_POST['usrid'])) {
$whatineed = "The updater have an user ID " . $_POST['usrid'];
} else {
$whatineed = "The updater have nothing to do, because an user ID have not been received.";
}
echo($whatineed);// this is the message TO modal
?>
<a userid="abc1" class="selectLink" href="#">click me to start update</a>
<div id="Contact" title="I have a message from the update scrtipt">
<p></p>
</div>
$(".selectLink").click(function (e) {
var userid = $(e.target).attr("userid");
var _self = this;
$.post(site_url("user/update.php"), {
usrid: usrid
}, function (data) { //message FROM update.php
var dlg = $('#Contact'),
txt = $('#Contact p');// or txt = dlg.find("p");
txt.html(data);
dlg.dialog({
resizable: false,
height: 150,
modal: true,
buttons: {
"OK": function () {
$(this).dialog("close");
}
}
});
})
return false;
});