작성
·
201
0
Uncaught TypeError: Cannot set property 'innerHTML' of null
at XMLHttpRequest. (form.html:30)
(anonymous) @ form.html:30
load (async)
sendAjax @ form.html:27
(anonymous) @ form.html:17
이런 오류가 나는데 어떤게 문제 일까요?
코드는 아래와 같습니다
<!doctype html>
email form
email:
ajaxsend
document.querySelector('.ajaxsend').addEventListener('click',function(){
var inputdata = document.forms[0].elements[0].value;
sendAjax('http://127.0.0.1:3000/ajax_send_email',inputdata);
})
function sendAjax(url, data){
var data = {'email' : data};
data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.open('POST',url);
xhr.setRequestHeader('Content-Type',"application/json");
xhr.send(data);
xhr.addEventListener('load',function(){
var result = JSON.parse(xhr.responseText);
if(result.result != "ok")return;
document.querySelector(".result").innerHTML = result.email;
});
}