Categories: php, jquery, ajax

i want to send variable from one php page to another using jquery ajax

1 answer

Page 1 js:

  $(document).ready(function () {     $(".btn").on("click", function () {       $.ajax({         type: "GET",         url: "./page.php",         data: { name: "peter" },         success: function (data) {           alert(data);         },       });     });   }); 

Page 2 php:

<?php if(isset($_GET['name'])){     $name =$_GET['name'];     echo $name; } else{     echo "data not recived"; }   ?> 

Here, at the first page it triggers the alert and displays the value of "name" but it doesn't return the value to the destination url and it executes the else statement. Thanks for your help!

All answers to this question, which has the identifier 61184146

The best answer:

Sorry, I don't have enough reputation to leave comment. I tested your code, and your code is correct. I don't know why you cannot get your expected result. But I think you can try the go to http://localhost/page.php?name=aaa in your browser to see it will show "aaa" or "data not recived"

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data