正在试图挽救端点URL,钥匙和令牌到数据库,但我得到一些错误而使代码下来PLZ检查如何存储在数据库中的网络推端点URL
main.js
var endpoint = sub.endpoint ;
var key = btoa(String.fromCharCode.apply(null, new Uint8Array(sub.getKey('p256dh')))) ;
var token = btoa(String.fromCharCode.apply(null, new Uint8Array(sub.getKey('auth')))) ;
var axn = "subscribe" ;
$.ajax({
type: "POST",
url: "push_endpoint_save.php",
dataType : "json",
data:{
"endpoint" : endpoint,
"key" : key,
"token" : token,
"axn" : axn
}, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: "application/json; charset=utf-8", // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data){
console.log(data) ;
}
});
push.php
var_dump($_POST); die;
session_start();
if (isset($_SESSION['user_id'])) {
$userid = $_SESSION['user_id'];
}
else {
$userid ="";
}
// CONNECT TO THE DATABASE
include_once("php_includes/conn.php");
$_POST = json_decode(file_get_contents('php://input'), true);
$endpoint = $_POST['endpoint'] ;
$key = $_POST['key'] ;
$token = $_POST['token'] ;
$axn = $_POST['axn'] ;
$user_likes = mysqli_query($conn,"INSERT INTO endpointurl (endpoint,p256dh,auth) VALUES ('$endpoint','$key','$token')");
if ($conn->query($user_likes) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $user_likes . "<br>" . $conn->error;
}
,这是数据库结构 enter image description here
时无法receieve端点,重点,在php文件标记
寻找解决方案!下面的代码作品答案,即使我认为我的代码可能工作,但真正的问题我的服务器不接受url作为我的PHP文件的参数,所以我通过替换var –