我想从同一页面上php _ $ POST中的ajax帖子获取成功响应,因此我可以将其设为变量并进一步使用它。当我在一个段落的ID中发布ajax帖子时,它可以工作,但是该页面将不再看到该帖子。响应应该是来自选择选项值的ID。
我尝试了在没有网址的情况下工作,因此该帖子将显示在同一页面上,但是随后它显示了我页面的全部内容,而不是成功的响应,并且使用了网址,我不知道如何在索引页面上显示它
索引页:
$query = $conn->query("SELECT Opleidingnaam, OpleidingID FROM Opleidingen
INNER JOIN PsKpEntity ON Opleidingen.OpleidingID = PsKpEntity.PsID
WHERE PsKpEntity.deleted = 0 ORDER BY Opleidingnaam");
echo '<select id="oplselect" class="oplselect" name="opleidingen">';
echo '<option value="">Selecteer opleiding</option>';
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='" . $row['OpleidingID'] ."'>" . $row['Opleidingnaam'] ."</option>";
}
echo '</select>';
echo '<input type="submit" name="submit" id="oplsubmit" value="Volgende stap" class="nexttab"> </input>';
?>
</div>
<div class="tab-pane" id="datumlocatie">
<div class="showoplnaam"></div>
<?php
$opleidingid = $_POST['opleidingid'];
echo $opleidingid;
?>
<p id="test"></p>
页脚index.php下面的js
$("#oplsubmit").click(function(){
var opleidingid = $('#oplselect option:selected').val();
$.ajax({
type: "POST",
url: "/wp-content/themes/tweb/oplselect.php",
data: {'selected':opleidingid},
success: function(data){
console.log(data);
// $('#test').html(data);
},
error: function(e){
console.log(e.message);
}
});
var li_count = $('.nav-tabs li').length;
var current_active = $('.nav-tabs li.active').index();
if(current_active<li_count){
$('.nav-tabs li.active').next('li').find('a').attr('data-toggle','tab').tab('show');
var txt = $(".oplselect option:selected").text();
var val = $(".oplselect option:selected").val();
$('.showoplnaam').html('Uw selectie: ' + txt);
}else{
}
});
opl选择页面
<?php
$opleidingid = $_POST['opleidingid'];
echo $opleidingid;
?>