I am a newbie in web development and I want to see automatically my newly added data without refreshing the page. Just like in Facebook, when you post something on your wall the moment you press the post button it will appear automatically on your wall without refreshing the page. Is it possible using php? Can i seek some example coming from you experts? Thank you very much.
You can use ajax calls with jquery so your uploaded data shows in real time. For example
HTML
<input type="text" name="first" id="first">
<button id="subm"></button>
<div id="content"></div>
JAVASCRIPT (JQUERY)
$("#subm").click(function(){
var first_value = $("#first").val();
$.ajax({
type:"POST",
url:your_script.php,
data: {mydata:first_value}
success: function(response){ $("#content").html(response); }
});
});
your_script.php will process the data you've sent trough ajax and return a result, which you will see in real time with no need to refresh.
Check more about ajax here: http://api.jquery.com/jquery.ajax/
You can do it using jQuery and Ajax. Example:
$.ajax({
url: "test.php",
data: {"test": 123},
type: "POST",
success: function(data){
alert(data);
}
});
//test.php
if(isset($_POST['test']))
echo $_POST['test'];
In the success
function, you can do anything you want with the data variable, which contains the contents of the page where you sent a request to (in this case: 123
)
A tutorial which might help you: http://blog.teamtreehouse.com/beginners-guide-to-ajax-development-with-php