dongquxiao8545 2015-06-25 16:47
浏览 13
已采纳

试图把两个javascripts

I'm trying to put two onClick functions, but when i put them together I get an error. And first function ain't working, here is my script. As you can see im trying to call insertData function and then reload page with this function window.location.reload(). Bellow the script there is photo with an error.

if ($canEdit) {
        $s .= ("
\t\t".'<a href="#">'
               . "
\t\t\t".'<img src="./images/icons/tick.png" alt="' . $AppUI->_('Check') 
               . '" border="0" width="12" height="12" onClick="javascript:insertData('. $currentTasken .', '.$currentUser.', \''.$currentSummary.'\', '.$currentPercent.', \''.$currentDescription.'\'); window.location.reload();" />' . "
\t\t</a>");
    }
    $s .= "
\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); ?>;
    var currentSummary = <?php echo json_encode($currentSummary=$row[0]); ?>;

    function insertData(currentTasken, currentUser, currentSummary, 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) + "&currentSummary=" + encodeURIComponent(currentSummary) + "&currentPercent=" + encodeURIComponent(currentPercent)+ "&currentDescription=" + encodeURIComponent(currentDescription));
    }

    </script>

Here is the photo of the error: enter image description here

  • 写回答

1条回答 默认 最新

  • dou6577 2015-06-25 17:13
    关注
    onClick="javascript:doClickStuff('. $currentTasken .', '.$currentUser.', \''.$currentSummary.'\', '.$currentPercent.', \''.$currentDescription.'\');"
    

    Make you click function call the two functions and then set that as the click event

    function doClickStuff(data){
       insertData(data);
    }
    function insertData(currentTasken, currentUser, currentSummary, 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");
    
               //callback to reload page
            xmlhttp.onreadystatechange = function() {
               if (request.readyState == 4 && request.status == 200) {
                 window.location.reload();
               }
            }; 
                // Here, use the JS variables but, likewise, make sure they are escaped properly with `encodeURIComponent`
            xmlhttp.send("currentUser=" + encodeURIComponent(currentUser) + "&currentTasken=" + encodeURIComponent(currentTasken) + "&currentSummary=" + encodeURIComponent(currentSummary) + "&currentPercent=" + encodeURIComponent(currentPercent)+ "&currentDescription=" + encodeURIComponent(currentDescription));
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法