그래서 GET을 사용하여 AJAX 요청을 이미 수행 했으므로 대신 POST를 사용하여 행운을 시험해보고 싶었습니다. 그러나 어떤 이유로 데이터를 보내려고하면 콘솔에 이상한 메시지가 나타납니다. NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED : '자바 스크립트 구성 요소에 메서드를 호출 할 때 "사용 가능"이라는 메서드가 없습니다 : [nsIInputStream :: available] 말 그대로이게 무슨 뜻인지 전혀 모르겠다. 그리고 내가 요청한 load.php 파일에서 수행하는 모든 메쏘드가 저장할 변수를 에코하기 때문에 데이터가 통과하지 못한다. 그래서 자바 스크립트에서 뭔가.
요청한 첫 번째 페이지의 HTML입니다.
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<input id="input">
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
그리고 내 자바 스크립트 :
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
var data = "id="+document.getElementById("input").value;
xmlhttp.open("POST","load.php",true);
xmlhttp.send(data);
}
그리고 마지막으로, load.php에 대한 코드 :
$param = $_POST['id'];
if($param){
echo "Variable was stored.";
} else{
echo "Not working";
}
을 그리고 난이를 실행할 때마다, 나는 브라우저에서 "작동하지 않는"수 . 따라서 PHP 코드는 적어도 변수를 저장하려고 시도하지만 그렇지 않습니다. 고맙습니다!
'$ _POST '에'print_r'을 그냥 포함 시켜서 보았습니까? – naththedeveloper
"Array()"를 출력하고 있습니다. POST를 통해 액세스 할 경우 입력이