Javascript 从查询传递模式id,以便可以在另一个查询中使用
我想知道如何在模式上传递所选id 下面我有一个位于表格内的代码:Javascript 从查询传递模式id,以便可以在另一个查询中使用,javascript,php,mysql,sql,bootstrap-modal,Javascript,Php,Mysql,Sql,Bootstrap Modal,我想知道如何在模式上传递所选id 下面我有一个位于表格内的代码: <a type='button' id='seemore' data-toggle='modal' idNum='".$row['marriage_id']."' data-target='#see_more' class='glyphicon glyphicon-eye-open'></a> 结果将是从第一个查询中选择的id,其中它将是第二个查询中my where子句的参数 此示例使用异步数据加载。
<a type='button' id='seemore' data-toggle='modal' idNum='".$row['marriage_id']."'
data-target='#see_more' class='glyphicon glyphicon-eye-open'></a>
结果将是从第一个查询中选择的
id
,其中它将是第二个查询中my where子句的参数 此示例使用异步数据加载。用户单击按钮,请求被发送到服务器,当服务器响应时,程序的下一位被执行。在您的案例中,打开一个包含婚姻数据的模式。此系统的优点是,用户可以在解决请求时继续使用您的网页
使用onclick事件更新HTML中的链接
使用以下功能向页面添加脚本块
JavaScript:
function sendAjax(id, e) {
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 ) {
if(xmlhttp.status == 200){
//request is complete and loaded
//open the modal dialog or update it.
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}
}
}
xmlhttp.open("POST", "file.php", true); //true means asynchronously.
xmlhttp.send("idnum="+id);
}
id
作为post变量发送到服务器。用自己的php文件替换file.php
。在该php文件中,执行查询并将响应作为xml或JSON进行echo
//打开模式对话框或更新它。
:在这一行下面,您可以检索数据。此行位于检查数据是否已加载的事件处理程序中。由于服务器在if子句中响应了200
,因此我们可以假设有响应。如果是JSON,请使用JSON.parse(this.responseText)
。如果xml使用这个.responseXML
,那应该相当容易。我很难看清这里的大局。当有人单击链接时,您可以使用Ajax将id号发布到服务器。如果您使用mysqli
或PDO
,我无法弥补。从查询表中可以看出,表中所选行的结果将在模式中显示@鼠标器
function sendAjax(id, e) {
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 ) {
if(xmlhttp.status == 200){
//request is complete and loaded
//open the modal dialog or update it.
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}
}
}
xmlhttp.open("POST", "file.php", true); //true means asynchronously.
xmlhttp.send("idnum="+id);
}