htmlを開いても何も表示されません。
なぜでしょうか?
phpを直接開くと表示されます。
html
1<html lang="ja"> 2<body> 3 <script> 4 function event() { 5 $.ajax({ 6 type: 'POST', 7 url :'test.php', 8 data:{ key:value } 9 }).fail(function(){ 10 alert('error'); 11 }).done(function(){ 12 alert('success'); 13 }); 14 } 15 setInterval(event, 10); 16 </script> 17</body> 18</html>
php
1<!DOCTYPE html> 2<html lang="ja"> 3<body> 4 test 5</body> 6</html>
やっぱりダメです。
HTML
1<html lang="ja"> 2<body> 3 <script> 4 function event() { 5 $.ajax({ 6 type: 'POST', 7 url :'test.php', 8 data:{ key:value } 9 }).fail(function(){ 10 alert('error'); 11 }).done(function(){ 12 alert('success'); 13 }); 14 } 15 setInterval(event, 10); 16 </script> 17 <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script> 18</body> 19</html>
htmlを開いても
開くとはブラウザにhtmlのURLを打ち込むことです。
phpを直接開くとはphpのURLをブラウザに直接打ち込むことです。
エラーもサクセスも
何も表示されません。
URLはhttpsです。
ブラクラについて
setIntervalを使うと負荷が高くなるけどsetTimeoutを使えば10msごとでも負荷高くならないよね?
出来ました!!
出来ました!!!
HTML
1<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 2<div id="edit_area"></div> 3<script> 4var fn = function() { 5 $.ajax({ 6 type: 'post', 7 url: "test6.php", 8 success: function(result){ 9 document.getElementById('edit_area').innerHTML = result; 10 } 11 }); 12 setTimeout(fn,10); 13}; 14fn(); 15</script>
PHP
1<?php 2$result = file_get_contents ("10.txt"); 3file_put_contents("10.txt", $result + 1); 4echo $result; 5exit; 6?>
回答3件
あなたの回答
tips
プレビュー