我一直试图在以下方面寻求帮助,我需要在单击div之后将值传递给一个PHP表单,该表单将从服务器获取信息,将一些值传递给Jobseeker.php.html然后存储生成的HTML在$ output变量中,然后将输出变量中的HTML传递给页面上的div。以下是我的代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
</head>
<body>
<div class="self">
<div class="identity" style="display: none;">1234</div>
<div class="job_seeker_id" style="display: none;">18990</div>
<div class="vacancy_id" style="display: none;">787</div>
Helo
</div>
<div class="self">
<div class="identity" style="display: none;">444</div>
<div class="job_seeker_id" style="display: none;">5780</div>
<div class="vacancy_id" style="display: none;">787</div>
Hi there
</div>
<div class="self">
<div class="identity" style="display: none;">894</div>
<div class="job_seeker_id" style="display: none;">7800</div>
<div class="vacancy_id" style="display: none;">787</div>
ok
</div>
<div id="datahere"> Ok</div>
<script src="jquery.js"></script>
<script>
$( ".self" ).on("click", function( event ) {
var job_seeker_id = $(this).find(".job_seeker_id").text()
var vacancy_id = $(this).find(".vacancy_id").text()
$.ajax({
type: 'POST',
dataType: "",
url: 'get.php',
data: {
job_seeker_id, vacancy_id
},
success: function(response){
$("#datahere").html(response);
}
});
});
</script>
</body>
</html>
控制器PHP如下
<?php
if isset($_POST['job_seeker_id']) {
$result=$jobApplicationsTable->findAllWhere('WHERE `vacancy_id`=:vacancy_id AND job_seeker_id=:job_seeker_id', [':vacancy_id' => $_POST['vacancy_id'], ':job_seeker_id'=> $_POST['job_seeker_id'] ]);
foreach($result as $application)
{
ob_start();
require 'jobseeker.html.php';
$output=ob_get_clean();
}
}
?>
jobseeker.html.php如下
<div><h1>Job Title : <?=$application['title']?></h1></div>
<div><p>Applicant name : <?=$application['jobSeekerName']?></p></div>