gpt4 book ai didi

javascript - Uncaught SyntaxError : Unexpected token (, no error visible

转载 作者:行者123 更新时间:2023-12-03 08:51:58 25 4
gpt4 key购买 nike

我正在编写一个AJAX函数,但似乎有错误。我似乎找不到任何东西。请帮忙!我已经浏览了以下问题:thisthisthis,但是没有一个起作用。这是我的代码:

      function registerDevice(fp,uid)
{
$.ajax({
type: "POST",
async: true,
url: "backend.php",
data: {"fp": fp, "uid" : uid},
success: function(output) {
var json = eval('(' + output + ')');
var status = json['status'];
if(status == "success")
{
//redirect user.
setTimeout(function(){
//do what you need here
<?php
if(isset($_GET['goto']))
{
echo 'window.location.replace("'.$_GET["goto"].'");';
}
else
{
echo 'window.location.replace("index.php");';
}
?>
}, 2000);
}
else
{
$("#login-msg").text("Something went wrong. Please try again.");
$("#login-alert").fadeTo(4000, 500).slideUp(500, function(){
$("#login-alert").hide();
});
}
},
error: function(error) {
$("#login-msg").text("There was an unknown error.");
$("#login-alert").fadeTo(4000, 500).slideUp(500, function(){
$("#login-alert").hide();
});
}
});
}

它的名称如下:
    $('body').on("click", "#mybtn", function (e) {
registerDevice(result,uid);
});

这是我在Google Chrome浏览器中遇到的错误:
VM411:1 Uncaught SyntaxError: Unexpected token )
success @ login_alpha.php:344
j @ jquery.js:3148
fireWith @ jquery.js:3260
x @ jquery.js:9314
b @ jquery.js:9718

附言:第344行是指该行:
var json = eval('(' + output + ')');

编辑1:backend.php
<?php
$uid = $_POST['uid'];
$fp = $_POST['fp'];

//my code here.
$response_array['status'] = "success";
$response_array['type'] = "cookie";

?>

最佳答案

eval函数需要一个字符串来评估。您正在尝试评估我认为的JSON对象。

尝试:

var json = eval('(' + JSON.stringify(output) + ')');

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

关于javascript - Uncaught SyntaxError : Unexpected token (, no error visible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38113720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com