0

Is it possible to post value in the same page, and caught it in PHP tag without reloading the page?

I've been looking for some references from the Internet, such as using the session, cookies, ajax, etc. But, it can only be used once until the page is refreshed.

My purpose is to load the data from the database and display it in the html table.

I've tried using ajax like this :

$("#submit").click(function(){
    var abc = $("#text").val();
    var dataString = 'abc1='+ abc;

    $.ajax({
    type: "POST",
    url: "destination.php",
    data: dataString,
    cache: false,
    success: function(result){
        alert(result);
        }
    });
});

And caught it with:

<?php
    // if(isset($_POST)){
    $number = $_POST['abc1'];
    // }
?>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Zhumpex
  • 121
  • 1
  • 3
  • 17
  • You're on the right track with Ajax. Read and test: http://www.w3schools.com/ajax/ If you get stuck, come back, show us what you tried and we'll help you. – M. Eriksson Jun 22 '16 at 08:42
  • PHP code only runs on the server, so you have to make a new server request to execute any code you require. If you want to avoid refreshing the page to do this, you can use AJAX. There are plenty of articles, tutorials and questions covering this already. – Rory McCrossan Jun 22 '16 at 08:42
  • @MagnusEriksson : I was edit my question with something that I have tried – Zhumpex Jun 22 '16 at 08:53
  • You must output what you want your ajax request to fetch. Your ajax destination doesn't get "included" in your page. It basically just calls an url and returns the response. – M. Eriksson Jun 22 '16 at 08:57

0 Answers0