I create to file ajax.php
and jajaxget.php
.
script in ajax.php is-
<script>
var data={name:"nikhil"};
$.ajax({type:"post",url:"jajaxget.php",data: {name:"nikhil"},success:function(r,s){alert(s);alert(r);}});
</script>
and jajaxget.php is
<!doctype html>
<html>
<body>
<?php
echo $_POST["name"];
?>
ajax.php works fine and in alert i can see the data which i send. I get a success alert and this ALERT
But when i open the get.php file in browser there is nothing . "nikhil" should show on the page. but the page is blank . why data is not recived by jajaxget.php
file. It may be very foolish question .but please help
That should not show on the page when you open it on the browser because you are not passing any POST data when you do so. Your code is working as expected. I think your problem is you do not really get to understand how GET/POST works.
In the post environment variable the post data sent on request is stored. It is not stored forever nor as kind of a cookie. When you make another request, the variable will have different data according with the headers of the request.
So when you are using AJAX and send post data to your file, the return shows the "name" value you've passed because you've sent it on the request headers. However, when you request the page on a browser and you are not passing any POST data, that won't be shown, because nothing you've sent.
If you want your server to store that data, you may use databases or cookies for that.
For more information read some webpages online like http://www.w3schools.com/tags/ref_httpmethods.asp. And please try to understand a bit how the web works before filing it of low quality questions.
If you still have doubts, please ask me.