第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

XMLhttpRequest 返回空響應(yīng)的問題

XMLhttpRequest 返回空響應(yīng)的問題

藍(lán)山帝景 2021-08-20 17:41:37
我正在嘗試在我的網(wǎng)站中構(gòu)建一個(gè)新功能,這要求我從我在 Web 服務(wù)器上獲得的數(shù)據(jù)庫中檢索單個(gè)值。為此,我使用 php 腳本服務(wù)器端,它使用 msqli 從數(shù)據(jù)庫中檢索數(shù)據(jù)??蛻舳宋沂褂?Ajax 和 XMLhttpRequest 來調(diào)用 php 腳本。一切正常,我沒有任何錯(cuò)誤,只是我的 xml 總是有一個(gè)空響應(yīng),這讓我認(rèn)為我的 php 腳本有問題。你們能幫忙嗎?下面包含一些代碼。這是我的 php 腳本<?php$conn = new mysqli('localhost', 'nicolas', 'Password', 'RandomNumberHouse');if ($conn->connect_error) {    die("Connection failed: " . $conn->connect_error);    echo "error";} $HouseID = 6;$sql = "SELECT RandomVar FROM RandomVarHouse WHERE HouseID = $HouseID";$result = $conn->query($sql);$row = mysqli_fetch_array($result);$var = $row[2];echo $var;$conn-> close();?>這是我的 js 腳本function getRandomVar(){    xmlhttp = new XMLHttpRequest();    xmlhttp.open("GET","../inc/VarCommunication.php?");    xmlhttp.send();    xmlhttp.onreadystatechange = function() {        if (this.readyState === 4 && this.status === 200) {            var result = this.responseText;            updateBackgroundColor(result);        };      }}   function updateBackgroundColor(number){    if( number < 100){        document.getElementById('mainBody').style.backgroundColor = 'red';    }}
查看完整描述

1 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

you miss place semicolon in xmlhttp request. please try below code and verify result


  <script>

        function getRandomVar()

        {

            xmlhttp = new XMLHttpRequest();

            xmlhttp.open("GET","demo1.php");

            xmlhttp.send();

            xmlhttp.onreadystatechange = function()

            {

                if (this.readyState === 4 && this.status === 200)

                {

                    var result = this.responseText;

                    alert(result);

                    //updateBackgroundColor(result);

                }

              };

        }


    </script> 


查看完整回答
反對(duì) 回復(fù) 2021-08-20
  • 1 回答
  • 0 關(guān)注
  • 501 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)