How can I reload #order when button is clicked?
I have a php file that includes another 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>
I have tried to include the script in index.php and didn't work.
EDITED:
Simplified and remove irrelevant code:
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):
$(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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.