Why is request.status=0? There is no problem with php and browser return.

request.status=0, has checked several times and found nothing wrong. The code screenshot is as follows
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Document</title>
</head>
<style>
p {
  color:-sharpff0000;
}
</style>
<body>
<h1></h1>
<label for="">:</label>
<input type="text" id="keyword">
<button id="search"></button>
<p id="searchResult">

<script type="text/javascript"> document.getElementById("search").onclick = function() { var request = new XMLHttpRequest(); request.open("GET","http://t.com/ajax/server.php?number=" + document.getElementById("keyword").value); request.send(); request.onreadystatechange = function() { if (request.readyState === 4) { if(request.status == 200) { document.getElementById("searchResult").innerHtml = request.responseText; } else { alert(":request.status=" + request.status); } } else { alert("request.readyState=" + request.readyState); } } } </script> </body> </html>

Jul.30,2021

is cross-domain. Have you ignored 2 red error as big as the console?
the solution is nothing more than jsonp or server configuration to allow cross-domain, self-search engine


code I copied once, created a new folder, and then restarted the wampp, problem is gone, but innerHtml is invalid, innerText can, do not understand ah

Menu