+ 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?
13 odpowiedzi
+ 5
If you want to get the query string there is a fairly easy way:
https://www.sitepoint.com/url-parameters-jquery/
+ 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
+ 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
+ 3
Are you trying to access the php file through browser without parameters or is that what you get as request response?
+ 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.
+ 2
some possibilities to retrieve those data..? please I am stuck on this
+ 2
the method was of get type and I used $_GET ... to retrieve ... but seems like it's not working
+ 1
owh... I used get global variable to retrieve with the name of the data that passed
+ 1
I checked the request. it's working ...but can't retrieve the data
+ 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😣😣
+ 1
and giving the error as undefined index :name... which usually give when the field is not defined
0
I got this error as the request response...
- 1
brain bro...teach me some of basic