I create a html, and after I submit, the ajax should send a message to php, but my php doesn't get this data, please tell me how do I do, thank you.
function SendData(){
$.ajax({
type: "GET",
url: "client.php?m=submit",
success: function(data){
alert("success");
},
error: function(data){
alert("error");
}
});
}
php code always nothing, I know the m isn't exist, but I don't understand.
$message = isset($_GET['m']);
echo $message;
The problem is that you get a boolean with isset();
Do like this:
if(isset($_GET['m'])) {
$message = $_GET['m'];
echo $message;
}
you can try like
function SendData(){
$.ajax({
type: "GET", //send it through get method
url: "client.php",
data: {
m: submit // Here you can send multiple parameters
},
success: function(data){
alert("success");
},
error: function(data){
alert("error");
}
});
}
And you can get the data by
if(isset($_GET['m'])){echo $_GET['m'];} //gives submit
Change your code to
$message = isset($_GET['m']) ? $_GET['m'] : null;
echo $message;
the php isset()
always determine if a variable is set and is not NULL. It will return FALSE
if testing a variable that has been set to NULL. You can't echo the result outputted by isset directly using echo, use like this
$message= isset($_GET['m']) ? $_GET['m'] : ' ';
echo $message;
check the documention of isset here http://php.net/manual/en/function.isset.php