我有两个页面(结帐和订单页面)。
结帐页面包含一个confirme order
按钮。如果单击该按钮,订单页面将加载数据,而无需刷新页面。
我该怎么做。请点击我。
您可以使用
ajax 调用从"data.php"(或从任何获取数据的地方)获取 HTML,并将该 HTML 打印到结帐页面中的div 中。
$.ajax({
url: "data.php"
}).complete(function(result) {
$( div ).html(result);
});
与此类似的东西。
有关 Ajax 的更多信息 - http://api.jquery.com/jquery.ajax/
首先拿一个简单的按钮,在点击时调用一个jquery函数-
echo '<a href="#" id="button">Click to change</a>';
Jquery
<script type="text/javascript">
$(function() { // wrap inside the jquery ready() function
//Attach an onclick handler
$('#button').click(function(){
//Get the ID of the button that was clicked on (addition if you want any specific data, just pass that id in place of button)
var specific_id = $(this).attr("id");
$.ajax({
url: "yourPHP_data.php", //This is the page where you will handle your SQL insert
type: "POST",
data: "data=" + specific_id, //The data your sending to yourPHP_data.php
success: function(){
console.log("AJAX request was successfull");
},
error:function(){
console.log("AJAX request was a failure");
}
});
});
});
</script>
yourPHP_data.php页面包含要加载和显示的代码,并且您还可以找到已传递的数据-
$data = $_POST['data'];