Ajax1.html ファイルをFirefoxで実行すると正常に表示され、Google chromeで実行するとエラーになる。
Firefoxで実行は、サーバーはXAMPP、http://localhost/JavaScriptパーフェクトマスター/chap10/sec01/Ajax_html/Ajax1.html
で実行
Google chromeはサーバーは127.0.0.1:5500/Ajax_html/Ajax1.htmlで実行、VSCodeのGo Liveで実行しています。
今まで調べたこと、
Failed to load resource: the server responded with a status of 404 (Not Found),
405 エラー(Method Not Allowed)とは?その原因と解決方法,
faviconエラー解消方法として推奨されていた方法 ,
ですが、これはいろいろ試していた時のエラーとわからないところを検索したときの
項目です。よくわかりません。
VSCodeのGo Liveで実行できるようにしたいので、
どなたか教えてください。
質問内容がわかりにくいと思いますがよろしくお願いいたします。
](https://ddjkaamml8q8x.cloudfront.net/questions/2022-01-14/f860e2fd-f807-4f76-8b24-ac618890d9fc.png)]
html
1//Ajax1.html 2<!DOCTYPE html> 3<html> 4<head> 5 <meta charset="UTF-8" /> 6 <title>入力データをサーバーに送り、サーバー側で処理、返された結果をページに反映さする</title> 7 8 <script> 9 10 function requestSend() { 11 12 let request = new XMLHttpRequest(); 13 14 request.onreadystatechange = function(){ 15 16 let show = document.getElementById('show'); 17 18 if (request.readyState == 4) { 19 20 if (request.status == 200) { 21 22 show.textContent = request.responseText; 23 24 } else { 25 show.innerHTML = "サーバーエラーが発生しました。"; 26 } 27 28 } else { 29 show.innerHTML = "サーバーと通信中です..."; 30 } 31 } 32 request.open('GET', 'serverSide.php?name=' + 33 encodeURIComponent(document.frm.name.value), true); 34 35 request.send(); 36 } 37 document.addEventListener("DOMContentLoaded", function(){ 38 39 document.getElementById('btn').addEventListener('click', requestSend, false); 40 }, false); 41 </script> 42</head> 43<body> 44 <form name="frm"> 45 46 <label>お名前をどうぞ: 47 <input type="text" name="name" size="15" /> 48 </label> 49 50 <input type="button" id="btn" value="送信" /> 51 52 </form> 53 54 <p id="show"></p> 55 56</body> 57</html> 58 59
php
1//serverSide.php 2<?php 3sleep(3); 4print($_REQUEST['name'].'さん、こんにちは!'); 5?> 6
