php初心者です。
いまurlのパラメーター名のjsファイルが存在するか調べてJavascriptのifで結果が分かるようなプログラムを作っています。
実行すると真っ白の画面だけが出て何も表示されません。
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="utf-8" /> 5 <title>test</title> 6 7<script> 8//url取得------------------------------------------------------ 9const url = location.href; 10var parameter = url.slice( 90 ) ; //90はurlのパラメーター前までの文字数です 11 12//存在確認----------------------------------------------------- 13function post() { 14xhr.open('POST', 'test.php', true); 15xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); 16var request = "kea=" + (parameter); 17xhr.send(request); 18} 19window.onload = function() { 20 xhr = new XMLHttpRequest(); 21 xhr.onload = function (e) { 22 if (xhr.readyState === 4) { 23 if (xhr.status === 200) { 24 var answer = document.getElementById('answer'); 25 var replr = xhr.responseText; 26 document.write(replr); 27 } 28 } 29 }; 30}; 31//結果----------------------------------------------------- 32document.write(replr); 33if ((replr) = 1) { 34 document.write("ある"); 35 36}else{ 37 document.write("ない"); 38} 39 40 41</script> 42 43</head> 44<body> 45</body> 46</html>
php
1<?php 2$arg1 = $_POST['kea']; 3$filename = "place/{$kea}.js"; 4if (file_exists($filename)) { 5 $answer = "1"; 6} else { 7 $answer = "2"; 8 touch($uidfile); 9} 10echo $answer; 11?>
php初心者なのでなるべく詳しく教えていただけるとありがたいです。
![guest](/img/icon/icnUserSample.jpg)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。