如何在单击另一个页面按钮时加载单页内容而不刷新页面

时间:2015-01-28 08:31:36

标签: php jquery ajax

我有两页(结帐订单页面)。
结帐页面包含confirme order按钮。如果单击该按钮, order 页面将加载数据而不刷新页面。

我该怎么做?请点击我。

2 个答案:

答案 0 :(得分:0)

您可以使用ajax调用从“data.php”获取HTML。 (或者从中获取数据的任何地方)并将HTML打印到结帐页面中的div。

$.ajax({
  url: "data.php"
}).complete(function(result) {
  $( div ).html(result);
});

类似的东西。

有关Ajax的更多信息 - http://api.jquery.com/jquery.ajax/

答案 1 :(得分:0)

首先拿一个简单的按钮并调用jquery函数onclick -

 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'];
相关问题