XMLHttpRequest的问题

时间:2017-06-21 08:54:05

标签: javascript php xmlhttprequest

我必须链接到网站上的数据库,但是我收到此错误,我不知道你的意思" XMLHttpRequest无法加载http://apptablet.altervista.org/Prova.php。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' null'因此不允许访问。" 这是在加载

中执行的功能
function fo() {
alert("Ciao");
    httpreq = new XMLHttpRequest();
    httpreq.onreadystatechange = function () {
        if (httpreq.readyState == 4 && httpreq.status == 200) {
            if (rip == 0) {
                alert(httpreq.responseText.split('-')[0]);
                document.getElementById("temp").value = httpreq.responseText.split('-')[0];
                alert(httpreq.responseText.split('-')[1]);
                if (httpreq.responseText.split('-')[1] == 1) {
                    document.getElementById("OnOff").value = "ON";
                }
                else {
                    document.getElementById("OnOff").value = "OFF";
                }
                rip++;
            }
        }
    };
    httpreq.open("POST", "http://apptablet.altervista.org/Prova.php");
    httpreq.responseType = "text";
    httpreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    httpreq.send();
}

0 个答案:

没有答案