[英]Reload DIV by clicking button inside DIV
How can I reload #order when button is clicked? 单击按钮后如何重新加载#order?
I have a php file that includes another php: 我有一个包含另一个php的php文件:
index.php: index.php:
<div id="order">
<?php include('order.inc.php'); ?>
</div>
order.inc.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(){
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>
I have tried to include the script in index.php and didn't work. 我试图将脚本包含在index.php中,但没有工作。
EDITED: 编辑:
Simplified and remove irrelevant code: 简化并删除不相关的代码:
order.inc.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>
Try this (using objects ID): 试试看(使用对象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);
}
});
});
});
Note you could use the button value to pass any information to your PHP file. 注意,您可以使用按钮值将任何信息传递到您的PHP文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.