点击按钮后如何重新加载#order?
我有一个包含另一个php的php文件:
index.php:
<div id="order">
<?php include('order.inc.php'); ?>
</div>order.inc.php:
<div class="update_database" data-ref="1">Update</div>
<div class="update_database" data-ref="2">Update</div>
<script>
$('.update_database').click(function(){
var target_id = $(this).attr('data-ref');
var dataString = 'update=' + target_id;
$.ajax({
type: 'post',
url: 'post.php',
data: dataString,
success: function(data) {
var result = $.trim(data);
if (result == 'success') {
$('#order').load('order.inc.php'); <= this is where I am having problem with
} else if (result == 'accept') {
// do something else
} else {
console.log(data);
}
});
});
</script>我曾尝试在index.php中包含该脚本,但没有成功。
编辑:
简化并删除不相关的代码:
order.inc.php“
<div class="update_database" data-ref="1">Update</div>
<div class="update_database" data-ref="2">Update</div>
<script>
$('.update_database').click(function(){
alert('clicked');
$('#order').load('order.inc.php'); <= this is where I am having problem with
});
});
</script>发布于 2016-02-04 00:25:04
尝试此操作(使用对象ID):
$(document).ready(function(){
$("#button_id").change(function(){
var data=$(this).val();
var dataString = 'data'+data;
$.ajax({
type: "POST",
url: "your_php_file.php",
data: dataString,
cache: false,
success: function(html){
$("#content_destination_id").html(html);
}
});
});
});注您可以使用按钮值将任何信息传递到PHP文件。
https://stackoverflow.com/questions/35182171
复制相似问题