XMLHttpRequest无法加载[url]。预检的响应无效(重定向)

时间:2016-02-24 10:36:01

标签: javascript php jquery twitter-bootstrap

我遇到了这个问题,我可以找到任何答案。我尝试使用x-editable by bootstrap jquery来更新文本。我附上了图片error-image,下面是我的PHP代码

case 'update-number':

        if (isset($_POST['pk'])) {

            header('Content-Type: application/json;charset=UTF-8');
            header('Access-Control-Allow-Origin': '*');
            header('Access-Control-Allow-Methods: DELETE, HEAD, GET, OPTIONS, POST, PUT');
            header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
            header('Access-Control-Max-Age: 1728000');


            $user_id         = $_COOKIE['user_id'];
            $fed_id          = $_POST['pk'];
            $last_update     = date('Y-m-d h:i:s');
            $number = $_POST['value'];

            $query = "SELECT * FROM abc WHERE fed_id='$fed_id'";
            $result = $mysqli->query($query);
            $row= $result->num_rows;

                if ($row) {
                    $query = "UPDATE abc SET 
                    number      ='$number',
                    last_update         ='".$last_update."'
                    WHERE fed_id='".$fed_id."'";

                    $result = $mysqli->query($query);
                    echo "Updated";
                } else {
                    $query = "INSERT INTO abc (number, fed_id, user_id, last_update)
                              VALUES ('".$number."','".$fed_id."','".$user_id."','".$last_update."')";
                    $result = $mysqli->query($query);
                    echo "INSERTED";

                }
        }

        break;

2 个答案:

答案 0 :(得分:0)

我发现了这个问题。我使用没有www (ex: http://myurl.com)的基本网址我改为http://www.myurl.com并删除了代码中的标题。请参阅以下代码:

case 'update-number':

    if (isset($_POST['pk'])) {
        $user_id         = $_COOKIE['user_id'];
        $fed_id          = $_POST['pk'];
        $last_update     = date('Y-m-d h:i:s');
        $number = $_POST['value'];

        $query = "SELECT * FROM abc WHERE fed_id='$fed_id'";
        $result = $mysqli->query($query);
        $row= $result->num_rows;

            if ($row) {
                $query = "UPDATE abc SET 
                number      ='$number',
                last_update         ='".$last_update."'
                WHERE fed_id='".$fed_id."'";

                $result = $mysqli->query($query);
                echo "Updated";
            } else {
                $query = "INSERT INTO abc (number, fed_id, user_id, last_update)
                          VALUES ('".$number."','".$fed_id."','".$user_id."','".$last_update."')";
                $result = $mysqli->query($query);
                echo "INSERTED";

            }
    }

    break;

答案 1 :(得分:0)

这可能是由于协议无效

检查您的网址,使用http://而不是https://。

时也会发生此错误

我遇到了同样的问题并通过 http 替换 https 修复了此问题。