+ 1

How yo get the data from the url?

I am using AJAX in PHP and passing some data to the server through url. below is the code of the request that made.. ______________________________ xmlhttp.open("GET","abc.php?name=Alvin&age=12",true); ______________________________ where, abc.php is the another php file to which this request is made. and I want to get the URL data (name and age) in that file... how can I? should I go for $_GET?

15th Apr 2018, 4:51 AM
Saurav Kumar
Saurav Kumar - avatar
13 Answers
+ 5
If you want to get the query string there is a fairly easy way: https://www.sitepoint.com/url-parameters-jquery/
15th Apr 2018, 5:08 AM
Mickel
Mickel - avatar
+ 3
it depends on how the data is sent through the ajax request $.ajax ({ type: "POST", url: "abc.php", data: { 'test' : item }, success: function(result) { console.log(result); } }); if your type is post,use $_POST and vice-versa
15th Apr 2018, 5:01 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 3
in php you should have something like... if( isset($_POST['test'])) { $data=$_POST['test'] } the "if" statement isnt necessary,just to ensure $data wouldn't be null
15th Apr 2018, 5:07 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 3
Are you trying to access the php file through browser without parameters or is that what you get as request response?
15th Apr 2018, 5:21 AM
Toni Isotalo
Toni Isotalo - avatar
+ 3
That’s weird. You can try to use onreadystatechange even handler and check if the status is 200 but I don’t think it makes any different.
15th Apr 2018, 5:29 AM
Toni Isotalo
Toni Isotalo - avatar
+ 2
some possibilities to retrieve those data..? please I am stuck on this
15th Apr 2018, 5:03 AM
Saurav Kumar
Saurav Kumar - avatar
+ 2
the method was of get type and I used $_GET ... to retrieve ... but seems like it's not working
15th Apr 2018, 5:07 AM
Saurav Kumar
Saurav Kumar - avatar
+ 1
owh... I used get global variable to retrieve with the name of the data that passed
15th Apr 2018, 5:10 AM
Saurav Kumar
Saurav Kumar - avatar
+ 1
I checked the request. it's working ...but can't retrieve the data
15th Apr 2018, 5:10 AM
Saurav Kumar
Saurav Kumar - avatar
+ 1
yes I checked whether the get is set or not😣😣... and echo a message there.. something like this... if(isset($_GET['name'])) { echo ('recieved'); } else{ echo('failed'); } just checking the name field for now...the control enters in the if statement but when I use the get to get the data it shows... nothing😣😣
15th Apr 2018, 5:16 AM
Saurav Kumar
Saurav Kumar - avatar
+ 1
and giving the error as undefined index :name... which usually give when the field is not defined
15th Apr 2018, 5:17 AM
Saurav Kumar
Saurav Kumar - avatar
0
I got this error as the request response...
15th Apr 2018, 5:22 AM
Saurav Kumar
Saurav Kumar - avatar
- 1
brain bro...teach me some of basic
16th Apr 2018, 4:20 AM
nahid hasan