这将从mysql数据库中打印作业描述,作业ID和作业名称。它还有点击用户按钮可以选择作业
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function insert_job_f(jid)
{
//debugger;
var jidVal=$("#jid-"+jid).val();
$.ajax
({
type:'post',
url:'insert_job.php',
data:{
insert_job:"insert_job",
jid:jidVal
},
success:function(response) {
alert(response);
if(response=="success")
{
//window.location.href="main.php";
}
else
{
//alert("Wrong Details");
}
}
});
}
</script>
*****这是jquery脚本*****
<?php
if(isset($_POST['jid']))
{
$host="localhost";
$username="Ahad";
$password="abc.123";
$databasename="vsm";
$connect=mysqli_connect($host,$username,$password);
$db=mysqli_select_db($connect,$databasename);
$h=$_POST['jid'];[enter image description here][1]
$select_data=mysqli_query($connect,"INSERT INTO ff (jid) VALUES (19)");
if($select_data===FALSE)
{
echo mysqli_error($connect);
exit();
}
else
{
echo "successfully registered";
}
exit();
}
?>
***** **** insert_job.php
{{1}}
如果数据在循环中一次又一次地发送硬编码值,我怎样才能发送数据
下面的图片显示用于测试的硬编码值是递归地在数据库中进行的
答案 0 :(得分:0)
完全删除
<script type="text/javascript">
$("#submit-<?php echo $record['jid'];?>").click(function(e){
e.preventDefault();insert_job_f(<?php print($record['jid']); ?>);
});
</script>
并将onclick
事件直接附加到您的提交按钮:
<input type="submit" class="btn" value="Select" id="submit-<?php echo $record['jid'];?>" onclick="insert_job_f(<?php print($record['jid']); ?>)" />
我不确定如何处理preventDefault()
,但您可以将其附加到insert_job_f()
函数。