簡體   English   中英

未捕獲的SyntaxError:意外的令牌<ajax調用jsonp

[英]Uncaught SyntaxError: Unexpected token < ajax call jsonp

正如標題所述,在Chrome遠程調試中收到此錯誤。 我試圖將ajax請求(jsonp)發送到localhost中的.php文件,然后在掃描QR碼后使用QR碼中的URL對數據庫執行某些操作。 但是,我收到了這個錯誤。

我知道jsonp與json不同並使用不同的語法,但是我使用的代碼用於其他ajax調用。 我無法弄清楚問題,並希望得到一些幫助。

以下是代碼:

.html文件

<!DOCTYPE html>
<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <title></title>
    </head>
    <body>

        <div data-role="page" id="home">
            <div data-role="header">
                <h1></h1>
            </div>

            <div data-role="main" class="ui-content">
                <p>
                    <a target="_blank" href="javascript:scan();" style="text-decoration: none"><button>Scan</button></a>
                </p>
            </div>
        </div>

        <div data-role="page" id="display">
            <div data-role="header">
                <h1>Display</h1>
            </div>

            <div data-role="main" class="ui-content">
                <table data-role="table" data-mode="column" id="allTable" class="ui-responsive table-stroke">
                    <thead>
                        <tr>
                            <th>Name</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>

        <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
        <script type= "text/javascript" src="js/jquery-3.1.1.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script>
            function scan()
            {
                cordova.plugins.barcodeScanner.scan(
                    function (result) {
                        if(!result.cancelled)
                        {
                            if(result.format == "QR_CODE")
                            {
                                var value = result.text;

                            $.ajax({
                                    type: "GET",
                                    url: value + '?callback=?',
                                    dataType: 'JSONP',
                                    async: false,
                                    jsonp : "callback",
                                    jsonpCallback: "jsonpcallback",

                                    success: function jsonpcallback(response)
                                    {
                                        if (response == "Success") 
                                        {
                                            alert(response);
                                        } 
                                        else
                                        {
                                            alert(response);
                                        }
                                    }
                                  });

                            }
                        }
                    },
                    function (error) {
                        alert("Scanning failed: " + error);
                    }
               );
            }
        </script>
    </body>
</html>

.php文件

<?php

header('Content-Type: application/json');

require 'dbcon.php';

session_start();

$acc_points = $_SESSION["acc_points"];
$acc_id = $_SESSION["acc_id"];

$result = $con->prepare(" UPDATE `points` SET `acc_points` = acc_points+1  WHERE `acc_id` = ? ");
$result->bind_param("i", $acc_id);
$result->execute();

if($acc_points != null)
  {
      $response = "Success";
      echo $_GET['callback'] . '(' . json_encode($response) . ')';
  }
  else
  {
      $response = "Failed. Please try again.";
      echo $_GET['callback'] . '(' . json_encode($response) . ')';
  }  



    //connection closed
    mysqli_close ($con);

?>

錯誤是:
致命錯誤 :未捕獲異常'mysqli_sql_exception',消息'重復條目'12'用於C:\\ xampp \\ htdocs \\ MP \\ appqrcode.php中的鍵'PRIMARY':14堆棧跟蹤:#0 C:\\ xampp \\ htdocs \\ MP \\ appqrcode.php(14):在第14行的C:\\ xampp \\ htdocs \\ MP \\ appqrcode.php中拋出mysqli_stmt-> execute()#1 {main}

通過更改表的主鍵解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM