0

该脚本在一侧有效,但在另一侧无效。它得到一个未捕获的类型错误:无法调用未定义的方法“打开”。脚本放在两边的同一个位置...

此代码用于根据用户选择向 db 1-5 发送评级。

function send_ajax(bewertung, click) {
    if (click) {
        alt = userrating[{TOPIC_ID}];
        userrating[{TOPIC_ID}] = bewertung;
        xmlhttp.open("GET", "bewertung.php?{BEWERTUNGSVAR}&wertung=" + bewertung, true);
        xmlhttp.send();
        xmlhttp.onreadystatechange = function () {
            var a = new Date();
            a = new Date(a.getTime() + 1000 * 60 * 60 * 24 * 365);
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText) {
                    document.getElementById("ratingdesc").innerHTML = "{L_RATINGCOUNTED}";
                } else {
                    userrating[{TOPIC_ID}] = alt;
                    document.getElementById("ratingdesc").innerHTML = "Bewertung fehlgeschlagen... bitte nochmals versuchen!";
                }
            }
        }
    } else {
        if (bewertung) {
            document.getElementById("ratingstarbg").style.backgroundPosition = "0 -" + (bewertung * 17) + "px";
        } else {
            if (typeof userrating[{TOPIC_ID}] == 'undefined') {
                document.getElementById("ratingstarbg").style.backgroundPosition = "0 -{STARTBGPOS}px";
            } else {
                document.getElementById("ratingstarbg").style.backgroundPosition = "0 -" + (userrating[{TOPIC_ID}] * 17) + "px";
            }
        }
    }
}

这就是它在 HTML 中的调用方式

<div style="float:left">
<span id="ratingstarbg" class="star" style="background-position: 0 -{STARTBGPOS}px">
<a class="ratestar" href="javascript:send_ajax(1,true);" onmouseover="javascript:send_ajax(1,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(2,true);" onmouseover="javascript:send_ajax(2,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(3,true);" onmouseover="javascript:send_ajax(3,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(4,true);" onmouseover="javascript:send_ajax(4,false);" onmouseout="javascript:send_ajax(0,false);"></a>
<a class="ratestar" href="javascript:send_ajax(5,true);" onmouseover="javascript:send_ajax(5,false);" onmouseout="javascript:send_ajax(0,false);"></a>
</span>
</div>
4

1 回答 1

0

也许您没有在 xmlhttp 变量中实例化 XMLHttpRequest 对象。你可以尝试把

var xmlhttp = new XMLHttpRequest();

函数内部。

如果您需要兼容 IE5 和 IE6:

var xmlhttp;
if (window.XMLHttpRequest)
{
    xmlhttp=new XMLHttpRequest();
}
else
{
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
于 2013-11-12T16:42:45.213 回答