0
연락처 페이지 설정에 대한 튜토리얼을 따라했는데 어떤 이유로 인해 submit을 눌렀을 때 submitForm이 정의되지 않았다는 오류 메시지가 콘솔에 표시됩니다. 내 문제는 다른 웹 사이트에서 작동하도록 동일한 코드가 있지만 동일한 코드를 복사해도 작동하지 않는다는 것입니다. 여기Php 문의 양식 참조 오류
function _(id){ return document.getElementById(id); }
function submitForm(){
_("mybtn").disabled = true;
_("status").innerHTML = 'please wait ...';
var formdata = new FormData();
formdata.append("n", _("n").value);
formdata.append("e", _("e").value);
formdata.append("m", _("m").value);
var ajax = new XMLHttpRequest();
ajax.open("POST", "example_parser.php");
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
if(ajax.responseText == "success"){
_("my_form").innerHTML = '<h2>Thanks '+_("n").value+', your message has been sent.</h2>';
} else {
_("status").innerHTML = ajax.responseText;
_("mybtn").disabled = false;
}
}
}
ajax.send(formdata);
}
내 PHP 코드 :
<?php
if(isset($_POST['n']) && isset($_POST['e']) && isset($_POST['m'])){
$n = $_POST['n']; // HINT: use preg_replace() to filter the data
$e = $_POST['e'];
$m = nl2br($_POST['m']);
$to = "[email protected]";
$from = $e;
$subject = 'Contact Form Message';
$message = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p>'.$m.'</p>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
if(mail($to, $subject, $message, $headers)){
echo "success";
} else {
echo "The server failed to send the message. Please try again later.";
}
}
?>
당신은 내가 기능을하지만 오류가 정의에서 볼 수 있듯이 여기 내 JS 코드입니다. 어떤 도움이라도 대단히 감사하겠습니다.
어떻게 HTML에 javascript를 넣고 있습니까? '