내 웹 사이트 (www.chrisanstey.co.uk)에서 AJAX 문의 양식을 실행하고 있습니다.이 양식은 Firefox에서만 제출하는 것이 아니라 다른 모든 브라우저에서 완벽하게 작동합니다.AJAX 양식 제출 (Firefox에만 해당)
<?php
$to = "[email protected]"; //This is the email address you want to send the email to
if(!isset($_GET['action']))
{
die("You must not access this page directly!"); //Just to stop people from visiting contact.php normally
}
/* Now lets trim up the input before sending it */
$name = trim($_GET['name']); //The senders name
$email = trim($_GET['email']); //The senders email address
$subject = "A message sent from " . $name . " on Chris Anstey's portfolio"; //The senders subject
$message = trim($_GET['msg']); //The senders message
mail($to,$subject,$message,"From: ".$email.""); //a very simple send
echo 'contactarea|<p>Thank you '.$name.' for your message, I will reply to you as soon as I can.</p>'; //now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
?>
또한 다음과 같은 자바 스크립트 파일 : 양식은 다음과 같은 PHP 파일을 사용합니다
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sendemail() {
var msg = document.contactform.msg.value;
var name = document.contactform.name.value;
var email = document.contactform.email.value;
document.contactform.send.disabled=true;
document.contactform.send.value='Sending....';
http.open('get', 'contact.php?msg='+msg+'&name='+name+'&email='+email+'&action=send');
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
양식은 다음과 같은 HTML로 템플릿을 호출되고, 워드 프레스 페이지에 있습니다 :
<div id="contactarea">
<form name="contactform" id="contactform">
<p>Full Name:<br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="name"></span></p>
<p>Email:<br />
<span class="wpcf7-form-control-wrap your-email"><input type="text" name="email"></span></p>
<p>Message:<br />
<span class="wpcf7-form-control-wrap your-message"><textarea name="msg" rows="6" id="textarea"></textarea></span></p>
<p><input type="submit" value="Send Email" name="send" id="submitbutton" onClick="sendemail();"></p>
</form>
</div>
누구든지 Firefox에서 작동하지 않는 AJAX에 대해 생각해 보거나 비슷한 문제가 발생하는 경우 회신 해주십시오. 어떤 도움을 많이 주시면 감사하겠습니다!
양식을 제출할 때 사용자가 양식에 입력 한 내용을 전자 메일로 보내야하며 양식을받은 사실을 알리는 작은 메시지를 제공해야합니다. 테스트 할 때 PHP 쿼리를 표시하기 위해 URL이 변경됩니다. PHP 쿼리가 표시되지 않고 전자 메일이 전송되지 않습니다. 어떤 아이디어? –
오, 알았어. 그럼, 입력 내용을 양식 안에 넣지 않으면 설정됩니다. 양식 태그를 꺼내십시오. 또한,'input type = "submit"'을'input type = "button"'s으로 변경해야합니다 – Rahly