Javascript 由于word导致的引用错误

Javascript 由于word导致的引用错误,javascript,php,mysql,Javascript,Php,Mysql,我需要在数据库中写一个字,我不能保证我得到一个错误:ReferenceError:Patikrinta未定义这是我的ajax脚本,它将数据发送到php文件。贝娄有php脚本,如果你需要它。无法在stackowerflow中找到解决方案 $s .= "\n\t<td>"; $canEdit = getPermission('tasks', 'edit', $a['task_id']); $canViewLog = getPermission('task_log', 'view', $a

我需要在数据库中写一个字,我不能保证我得到一个错误:
ReferenceError:Patikrinta未定义
这是我的ajax脚本,它将数据发送到php文件。贝娄有php脚本,如果你需要它。无法在stackowerflow中找到解决方案

$s .= "\n\t<td>";
$canEdit = getPermission('tasks', 'edit', $a['task_id']);
$canViewLog = getPermission('task_log', 'view', $a['task_id']);
$currentTasken=$a['task_id'];
$currentUser=$AppUI->user_id;
$currentPercent="5";
$currentDescription="Patikrinta";
if ($canEdit) {
    $s .= ("\n\t\t".'<a href="#">'
           . "\n\t\t\t".'<img src="./images/icons/tick.png" alt="' . $AppUI->_('Check') 
           . '" border="0" width="12" height="12" onclick="javascript:insertData('. $currentTasken .', '.$currentUser.', '.$currentPercent.', '.$currentDescription.')" />' . "\n\t\t</a>");
}
$s .= "\n\t</td>";
?>
<script type="text/javascript">

// Note that you should use `json_encode` to make sure the data is escaped properly.
var currentTasken = <?php echo json_encode($currentTasken=$a['task_id']); ?>;
var currentUser = <?php echo json_encode($currentUser=$AppUI->user_id); ?>;

function insertData(currentTasken, currentUser, currentPercent, currentDescription)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("POST","modules/tasks/datafile.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

    // Here, use the JS variables but, likewise, make sure they are escaped properly with `encodeURIComponent`
    xmlhttp.send("currentUser=" + encodeURIComponent(currentUser) + "&currentTasken=" + encodeURIComponent(currentTasken) + "&currentPercent=" + encodeURIComponent(currentPercent)+ "&currentDescription=" + encodeURIComponent(currentDescription));
}

</script>
$s.=“\n\t”;
$canEdit=getPermission('tasks','edit',$a['task_id']);
$canViewLog=getPermission('task_log','view',$a['task_id']);
$currentTasken=$a['task_id'];
$currentUser=$AppUI->user\u id;
$currentPercent=“5”;
$currentDescription=“Patikrinta”;
如果($canEdit){
$s.=(“\n\t\t”。”);
}
$s.=“\n\t”;
?>
//请注意,您应该使用“json_encode”来确保正确转义数据。
var currentTasken=;
var currentUser=;
函数insertData(currentTasken、currentUser、currentPercent、currentDescription)
{
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
open(“POST”,“modules/tasks/datafile.php”,true);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
//在这里,使用JS变量,但同样地,请确保使用'encodeURIComponent'正确转义它们`
xmlhttp.send(“currentUser=“+encodeURIComponent(currentUser)+”和currentTasken=“+encodeURIComponent(currentTasken)+”和currentPercent=“+encodeURIComponent(currentPercent)+”和currentDescription=“+encodeURIComponent(currentDescription));
}
以下是我的php脚本:

<?php
$currentUser = isset($_POST['currentUser']) ? $_POST['currentUser'] : '';
$currentTasken = isset($_POST['currentTasken']) ? $_POST['currentTasken'] : '';
$currentPercent = isset($_POST['currentPercent']) ? $_POST['currentPercent'] : '';
$currentDescription = isset($_POST['currentDescription']) ? $_POST['currentDescription'] : '';
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    if(!$con)
        die('Could not connectzzz: ' . mysql_error());
    mysql_select_db("foxi" , $con) or die ("could not load the database" . mysql_error());

    $check = mysql_query("SELECT * FROM dotp_task_log");
    $numrows = mysql_num_rows($check);
    if($numrows >= 1)
    {
        //$pass = md5($pass);

        $ins = mysql_query("INSERT INTO dotp_task_log (task_log_creator, task_log_Task, task_log_description) VALUES ('$currentUser' , '$currentTasken', '$currentDescription')" ) ;

        if($ins)
        {
                $check = mysql_query("SELECT * FROM dotp_tasks");
                $numrows = mysql_num_rows($check);
                if($numrows > 1)
                {
                    //$pass = md5($pass);

                    $inss = mysql_query("UPDATE dotp_tasks SET task_percent_complete = '$currentPercent' WHERE task_id='$currentTasken'") ;

                    if($inss)
                    {
                        die("Succesfully added Percent!");
                    }
                    else
                    {
                        die("GERROR");
                    }

                }
                else
                {
                    die("Log already exists!");
                }
        }
        else
        {
            die("ERROR");
        }

    }
    else
    {
        die("Log already exists!");
    }


?>

您是否尝试在函数参数(即字符串)周围添加引号?JS正在查找对“Patikrinta”的引用,因为您没有在字符串周围添加引号。它应该更像这样:

javascript:insertData('. $currentTasken .', '.$currentUser.', '.$currentPercent.', \''.$currentDescription.'\')" />' . "\n\t\t</a>");
javascript:insertData('.$currentTasken'.'.$currentUser'.'.$currentPercent'.,\'.$currentDescription'.\')“/>”。“\n\t\t”);
其他参数之所以有效,是因为它们是作为数字传递的,Javascript将它们解释为数字。这里的区别是
$currentDescription
的值是
Patikrinta
,它不是一个数字,因此JS查找一个名为该值的变量或对象


作为旁注——如果可以的话,值得换用。函数已弃用。

您是否尝试过在函数参数周围添加引号,如:
javascript:insertData(“..currentTasken.”、“..currentUser.”、“..currentPercent.”、\'.$currentDescription.\”)“/>”。\n\t\t");如果您将currentDescription作为字符串传递,那么我认为您需要在其周围加引号,否则JS将尝试查找对“Patikrinta”的引用,该引用将失败(正如它所做的那样)。然后我会得到另一个错误`语法错误:非法字符javascript:insertData(1465,37,5,` WORKED thnx mate write in answers@AndyHanderson