我有一个名为search的AJAX函数,它接收ID和srcpath,然后将两个变量发送到PHP脚本,该脚本取消链接图像并从DB中删除文件目录。我尝试使用以下内容执行此操作,但是我一直收到'Uncaught SyntaxError:Unexpected token。'
echo "<input type='submit' value='Delete' onclick='search(".$fetch['id'].", ".$fetch['srcpath'].")'/>";
答案 0 :(得分:1)
$fetch['srcpath']
是一个字符串,因此您需要引用它:
echo "<input type='submit' value='Delete'
onclick='search(".$fetch['id'].", \"".$fetch['srcpath']."\")'/>";
也许这样更好:
echo "<input type='submit' value='Delete'
onclick='search({$fetch['id']}, \"{$fetch['srcpath']}\")'/>";