我通过验证程序运行了代码,但遇到了这个问题:
解析错误:语法错误,第4行的CODE中出现意外的'$ age'(T_VARIABLE)
解析CODE时出错
我是php的新手。
根据我的研究,人们说问题出在“ [/]”或“;”的错误位置。但是我认为那很好,那是怎么回事?
如果必要,我还可以发布html和js。
<?php
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$age = $_GET['age'];
$email = $_GET['email'];
echo "<h2>Response Demo Form</h2><h3> ";
echo "You submitted the following information<br><ul>";
echo "<li>Name: <strong> $firstName $lastName</strong></li>";
echo "<li>Age: $age</li>";
echo "<li>Age: $email</li>";
echo "</li></ul></h3>";
?>
let firstName = document.getElementById("firstName");
let lastName = document.getElementById("lastName");
let age = document.getElementById("age");
let email = document.getElementById("email");
let submitButton = document.getElementById("submitButton");
let responseHere = document.getElementById("responseHere");
submitButton.addEventListener('click', ajax);
function ajax(){
let xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
responseHere.innerHTML = this.responseText;
}
};
let httpString = "form_1.php?firstName=" + firstName.value + "&lastName=" + lastName.value + "&age=" + age.value + "&email=" + email.value;
console.log(httpString);
xmlhttp.open("GET", httpString, true);
xmlhttp.send();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="Lucas Baneke GD1A">
<title>Ajax form_1</title>
</head>
<body>
<h2>Form_2</h2>
<form>
<input type = "text" id = "firstName" name = "firstName" placeholder = "voornaam">
<input type = "text" id = "lastName" name = "lastName" placeholder = "achternaam">
<input type = "text" id = "age" name = "age" placeholder = "leeftijd">
<input type = "text" id = "email" name = "email" placeholder = "email">
<input type = "button" id = "submitButton" value = "submit">
</form>
<div id = "responseHere">hier komt de response</div>
<script src="script.js"></script>
</body>
</html>
错误:解析错误:语法错误,第4行的CODE中出现意外的'$ age'(T_VARIABLE)
解析CODE时出错
答案 0 :(得分:1)
如果在第4行之前有一个奇怪的不可见字符,则可能会发生这种情况。您可以通过使用诸如sublime text之类的文件打开文件来删除不可见字符,以使您可以查看不可见字符。