小编Cur*_*ewe的帖子

setTimeout连续循环,无需等待

我试图让setTimeout在15秒后重新运行它内部的函数,它不会等待15秒并且只是在一个恒定循环中执行它.

这是我目前的代码

function checkSession(x) {
http.abort();
http.open("GET", siteURL+"processes/ajax.php?call=check_session&string="+x+"&new="+Math.random(), true);
http.onreadystatechange = function() {
    if(http.readyState == 4) {
        if(http.responseText == true) {
            updateSession(x);
        } else {
            setTimeout(checkSession(x),15000);
        }
    }
}
http.send(null);
}
Run Code Online (Sandbox Code Playgroud)

我没有看到代码本身有任何问题,唯一不对的是它只是在不等待"15000"毫秒的情况下进行一个恒定的循环.

html javascript ajax

1
推荐指数
1
解决办法
1320
查看次数

复选框总是在javascript/php中返回true

我正在尝试使用Ajax/Javascript响应获取复选框的值,该响应将值传递给PHP,以便我可以根据值执行查询("已检查","未选中")

<input type="checkbox" name="status" onclick="updateStatus(<? echo $data['id']; ?>,this.checked)">
Run Code Online (Sandbox Code Playgroud)

函数"updateStatus"的Javascript/Ajax代码如下

function updateStatus(id,value) {
if (window.XMLHttpRequest) {
    http = new XMLHttpRequest()
} else if (window.ActiveXObject) {
    http = new ActiveXObject("Microsoft.XMLHTTP")
} else {
    alert("Your browser does not support XMLHTTP!")
}
http.abort();
http.open("GET", "../functions/ajax.php?check=update_status&id=" + id + "&checked="+value, true);
http.onreadystatechange = function () {
     if (http.readyState == 4) {
        alert(http.responseText);
     }
 }
 http.send(null)
Run Code Online (Sandbox Code Playgroud)

函数/ ajax.php中的PHP函数

if(isset($check) and $check == 'update_status' and isset($_GET['id'])){
    $id = mysql_real_escape_string($_GET['id']);
    $checked= mysql_real_escape_string($_GET['checked']);
if($checked == true) {
    echo "Checked"; …
Run Code Online (Sandbox Code Playgroud)

html javascript php ajax

0
推荐指数
1
解决办法
630
查看次数

执行array_key_exists会抛出错误

我收到的以下错误是

Warning: array_key_exists() expects parameter 2 to be array, 
null given in /home/*****/public_html/class/alerts.php on line 14
Run Code Online (Sandbox Code Playgroud)

在class/alerts.php的第14行,我看到以下行

if(!array_key_exists('flash_messages', $_SESSION)) $_SESSION['flash_messages'] = array();
Run Code Online (Sandbox Code Playgroud)

我正在使用问题在$ _SESSION里面,但我不确定

php session

0
推荐指数
1
解决办法
61
查看次数

标签 统计

ajax ×2

html ×2

javascript ×2

php ×2

session ×1