我想使用textbox
PHP
的模态
文本框代码:
<input type="text" id="weights" class="form-control" placeholder="Weight (lbs)" name="weight">
这是按钮代码:
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#exampleModalCenter" id="buttonx">Submit</button>
Jquery代码:
$(document).ready(function() {
$('#exampleModalCenter').on('show.bs.modal', function(e) {
var weight = document.getElementById("weights");
$.ajax({
type: 'post',
url: 'showResult.php',
data: 'weight=' + weight,
success: function(data) {
$('#fetched-data').html(data);
}
});
});
});
模态代码:
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Results</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="fetched-data">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
PHP:
<?php
$data=$_POST["weight"];
echo "The weight is $data";
?>
当我点击按钮时,没有任何内容真正显示出来。即使是模态,也不会出现。
答案 0 :(得分:-1)
您的代码中存在的问题
以下解决方案可能会解决您的问题:
希望这支笔 - &gt; https://codepen.io/afzal_coder/pen/rpKdgK解决您的疑问。
并将此代码添加到您的php文件中。
<?php
$data = $_POST['weight'];
echo $data;
?>