ajax quire에서 PHP 파일로 업데이트 할 HTML 요소를 가져 오려고하지만 작동하지 않습니다. 내 코드는 아래json ajax 업데이트 HTML 요소가 작동하지 않습니다.
<html>
<head>
<script src="jquery-3.1.0.min.js"></script>
</head>
<body>
<script>
var json = (function() {
\t var json = null;
$.ajax({
url: "test.php",
dataType: "json", //the return type data is jsonn
success: function(data){ // <--- (data) is in json format
json = data.test;
\t \t $('#demo').text(json.test1);
\t }
});
return json;
})();
</script>
<p id="demo"></p>
</body>
</html>
PHP 코드
<?php
header("Content-Type: application/json");
$test = array();
$test['test1'] = '1';
$test['test2'] = '2';
$test['test3'] = '3';
echo json_encode($test);
//echo nothing after this //not even html
?>
사람이 도와주세요 수 , 감사합니다
덕분에이 나는 변수에 넣어했다 생각했다,했다. – user2669997