当我的网站集成到iframe中时,我对ajax POST有问题。只有部分用户在Chrome中出现错误。我放了一个控制台错误的屏幕截图(由用户发送)。
有关的javascript在/js/open.min.js中:
/* (c) 2019 Lockee.fr */
function openLock(){
if($("#inputcode").val() != ""){
$.ajax({
type: 'POST',
async: false,
cache: false,
url: homeURL + 'ajax-open.php',
dataType: "json",
data: {id : $("#inputid").val(), code : $("#inputcode").val(), top : $("#inputtop").val()},
timeout: 3000,
success: function(data){
console.log(data);
if(data.open == 0){
$("#wrongcode").fadeIn(0).delay(1500).fadeOut(0);
} else {
if(data.redirect == 1){
if(data.top == 1){
top.location.href = data.content;
} else {
location.href = data.content;
}
} else {
$("#contentlock").html(data.content);
$("#isclose").hide();
$("#isopen").show();
$("#report").show();
}
}
}
});
}
}
function closeLock(){
lock.clearCode();
$("#contentlock").html("");
$("#isopen").hide();
$("#report").hide();
$("#isclose").show();
}
PHP代码:
<?php
include("functions.php");
if((!empty($_POST["id"]))&&(!empty($_POST["code"]))){
$id = addslashes($_POST['id']);
$code = htmlspecialchars($_POST['code']);
$infos = lockInfo($id);
if(($infos['action'] == "L")&&($_POST['top'] == 1)){
$top = 1;
$redirect = 1;
$content = $infos["content"];
} else if($infos['action'] == "L"){
$redirect = 1;
$top = 0;
$content = $infos["content"];
} else {
$redirect = 0;
$top = 0;
$content = displayContent($infos["action"], $infos["content"], $infos["linked"], false);
}
$open = 1;
if($infos['code'] == $code){
$open = 1;
} else {
$open = 0;
}
} else {
$open = 0;
}
if($open == 0){
$content = "";
}
$file = ["open" => $open, "content" => $content, "redirect" => $redirect, "top" => $top];
header('Content-Type: application/json');
echo json_encode($file);
?>
这是一个对某些用户不起作用的示例:
The code to open integrated lock is "123"
谢谢您的帮助!