简体   繁体   English

为什么此javascript无法正常工作?

[英]Why does this javascript won't work?

I would like to ask about this voting box that was included in our website files. 我想问一下我们网站文件中包含的投票箱。 Cause there seemed to be a problem with this. 原因似乎与此有关。 Whenever I click the "Click here to vote". 每当我点击“点击这里投票”。 Nothing happens, I do not have any idea why since I am not into java codings. 什么都没发生,我不知道为什么,因为我不喜欢Java编码。 I'd like to include the codes of it so you guys can take a look at. 我想包含它的代码,以便大家看看。

This is the voting box: http://i.stack.imgur.com/3LV8S.png 这是投票箱: http : //i.stack.imgur.com/3LV8S.png

So this is the code of where you are going to click it: 这是您要单击它的位置的代码:

if(isset($_SESSION['user'])) {
    odbc_exec($mssql, 'USE [ACCOUNT_DBF]');
    $votepoints = odbc_exec($mssql, 'SELECT votepoints FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
    echo 'Current Vote Points: <b><span id="currvp">'.odbc_result($votepoints, 'votepoints').'</span></b><br/><br/>';
    echo '<span id="takeitem"></span>';
    echo '<a href="javascript:voteTab();"><b>Click here to vote!</b></a>';
} else {
    echo '<b>You must login before you can vote!</b>';
}

This is the voteTab(); 这是voteTab(); function: 功能:

function voteTab() {
$.ajax({
    url: 'ajax.php?a=vote',
    type: 'GET',
    dataType: 'php',
    timeout: 1000,
    success: function(response){
      $(".boxcontent").html(response);
    }
});

This is the ajax:vote function: 这是ajax:vote函数:

if($_GET['a'] == 'vote') { // Vote Box
    odbc_exec($mssql, 'USE [ACCOUNT_DBF]');
    $userselect = odbc_exec($mssql, 'SELECT * FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
    $user = odbc_fetch_array($userselect);

    $diff1 = diff($user['lastvote1']);
    $diff2 = diff($user['lastvote2']);
    $diff3 = diff($user['lastvote3']);
    $votedtoday = 0;
    if($diff1['hours'] < 12)
        $votedtoday = $votedtoday + 1;
    if($diff2['hours'] < 12)
        $votedtoday = $votedtoday + 1;
    if($diff3['hours'] < 12)
        $votedtoday = $votedtoday + 1;
    echo 'Username: <b>'.$user['account'].'</b><br/><br/>';
    echo 'Current Vote Points: <b><span id="vpoints">'.$user['votepoints'].'</span></b><br/><br/>';
    echo 'You can vote <b><span id="vtoday"> '.(3 - $votedtoday).' </span></b> more times today.<br/><br/>';
    if($diff1['hours'] >= 12 || $diff2['hours'] >= 12 || $diff3['hours'] >= 12) {
        if(isset($_GET['submit'])) {
            if($_GET['submit'] == 1) {
                if($diff1['hours'] >= 12) {
                    odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET votepoints=votepoints+\'1\', lastvote'.mssql_escape_string($_GET['submit']).'=\''.date('d.m.Y H:i:s').'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
                }
            } elseif($_GET['submit'] == 2) {
                if($diff2['hours'] >= 12) {
                    odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET votepoints=votepoints+\'1\', lastvote'.mssql_escape_string($_GET['submit']).'=\''.date('d.m.Y H:i:s').'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
                }
            } elseif($_GET['submit'] == 3) {
                if($diff3['hours'] >= 12) {
                    odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET votepoints=votepoints+\'1\', lastvote'.mssql_escape_string($_GET['submit']).'=\''.date('d.m.Y H:i:s').'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
                }
            }
        }
        echo 'You gain 1 Vote Point each topsite.<br/>After voting you will be able to choose a free gift!<br/>Follow the instructions to vote for all 3 topsites.<br/><br/><div id="topsite" style="text-align: center;">';
        if($diff1['hours'] >= 12) {
            // Top of Games
            echo '<img src="img/tog.gif" /><br/><br/>';
            echo '<span id="votetext"><a onclick="vote(1, '.$diff2['hours'].', \''.$votelist2.'\', \''.$votelist3.'\');" href="'.$votelist1.'" target="_blank">Click here to continue!</a></span>';
        } elseif($diff2['hours'] >= 12 ) {
            // Xtreme Top 100
            echo '<img src="img/xtop100.jpg" /><br/><br/>';
            echo '<span id="votetext"><a onclick="vote(2, '.$diff3['hours'].', \''.$votelist2.'\', \''.$votelist3.'\');" href="'.$votelist2.'" target="_blank">Click here to continue!</a></span>';
        } elseif($diff3['hours'] >= 12) {
            // G Top 100
            echo '<img src="img/gtop100.jpg" /><br/><br/>';
            echo '<span id="votetext"><a onclick="vote(3, 0, \''.$votelist2.'\', \''.$votelist3.'\');" href="'.$votelist3.'" target="_blank">Click here to continue!</a></span>';
        }
        echo '</div>';
    } else {
        echo '<a href="javascript:voteItemTab();">Choose an item!</a>';
    }
}
/* VOTE BOX END */

I really need some answers of how it will work. 我真的需要一些如何工作的答案。

There probably problem with your PHP code that handle, database connection. 处理数据库连接的PHP代码可能存在问题。 Much better if you try to put error catch/break (on each line that handle db) and check the error.log to see what might break in background. 如果尝试将错误捕获/中断(在处理db的每一行上)并检查error.log以查看可能在后台中断的情况,那就更好了。

I've also notice some security flaw when you do AJAX request, MITM attack can change the response coming to your PHP code, try also to sanitize request and response. 我还注意到在执行AJAX请求时存在一些安全漏洞,MITM攻击可以更改对PHP代码的响应,还可以尝试清理请求和响应。

You're missing a closing curl brace on your function. 您缺少功能上的闭合花括号。

function voteTab() {
    $.ajax({
       url: 'ajax.php?a=vote',
       type: 'GET',
       dataType: 'php',
       timeout: 1000,
       success: function(response){
        $(".boxcontent").html(response);
       }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM