douku1984
douku1984
2015-01-28 08:31
浏览 155

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

I have two pages (checkout and order page).
The checkout page contains a confirme order button. If the button is clicked the order page loads the data without a page refresh.

How can i do that. Please click me.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwei7245
    dongwei7245 2015-01-28 08:37
    已采纳

    You can use an ajax call to get HTML from 'data.php' (or wherever you are getting your data from) and print that HTML into a div in checkout page.

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

    Something similar to this.

    For more on Ajax - http://api.jquery.com/jquery.ajax/

    点赞 评论
  • dongxie1907
    dongxie1907 2015-01-28 09:06

    First take a simple button and call a jquery function 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 page contain your code that you want to load and display, and you also find that data you have passed-

    $data = $_POST['data'];
    
    点赞 评论

相关推荐