I create the table and use ajax to pass data.
This is my ajax part, I put the parameter in URL, but php code doesn't read it.
$.ajax({
type:"POST",
url:"system_setting.php?p=add",
data:"username="+username+"&password="+password+"&nickname="+nickname+"&authority="+authority,
success:function(data){
viewData();
}
});
I use $page=isset($_GET['p'])?$_GET['p']:'';
to judgment parameter, but it doesn't read. Please teach me how should I do, thank you.
Use POST
instead and add p=add
in data instead url
$.ajax({
type:"POST",
url:"system_setting.php",
data:"p=add&username="+username+"&password="+password+"&nickname="+nickname+"&authority="+authority,
success:function(data){
viewData();
}
});
And in php
$page=isset($_POST['p'])?$_POST['p']:'';
You have to use only POST or only GET. Working example:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
var username="username";
var password="password";
var nickname="nickname";
var authority="authority";
$.ajax({
type:"POST",
url:"system_setting.php",
data:"p=add&username="+username+"&password="+password+"&nickname="+nickname+"&authority="+authority,
success:function(data){
alert(data);
}
});
</script>
In system_setting.php
$page=isset($_POST['p'])?$_POST['p']:'';
echo $page;
Give this a try:
var data = {};
data.username = username;
data.password = password;
data.nickname = nickname;
data.authority = authority;
data.p = “add”;
$.ajax({
type:"POST",
url:"system_setting.php",
data: data
}).done(function(data){
viewData();
});
Then when you need the data uses $_POST[]
eg $_POST['p']
Try this,ajax parameter "method" is used for POST and GET.
$.ajax({
method: "POST",
url: "system_setting.php",
data: { p:"add", username: "unsername", password: "password", nickname: "nickname", authority:"authority" },
success:function(data){
alert(data);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.