2010-11-30 4 views
0

내 웹 사이트 (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에 대해 생각해 보거나 비슷한 문제가 발생하는 경우 회신 해주십시오. 어떤 도움을 많이 주시면 감사하겠습니다!

답변

1

글쎄, 쿼리를 캐시 할 수 있습니다. 그것은 PHP를 호출하거나하지? 이 코드는 firefox에서 작동하지만 일단 작동하면 캐시해야하므로 다시 호출하지 않습니다.

+0

양식을 제출할 때 사용자가 양식에 입력 한 내용을 전자 메일로 보내야하며 양식을받은 사실을 알리는 작은 메시지를 제공해야합니다. 테스트 할 때 PHP 쿼리를 표시하기 위해 URL이 변경됩니다. PHP 쿼리가 표시되지 않고 전자 메일이 전송되지 않습니다. 어떤 아이디어? –

+0

오, 알았어. 그럼, 입력 내용을 양식 안에 넣지 않으면 설정됩니다. 양식 태그를 꺼내십시오. 또한,'input type = "submit"'을'input type = "button"'s으로 변경해야합니다 – Rahly

0

나는 파이어 폭스에서 테스트했고 아약스 호출 그래서 우리는 오류 메시지

EDIT 무엇을 볼 수있는 파이어 폭스에 불을 지르고 부가 기능을 설치하려고 .. 난 그게 문제라고 생각 해달라고 ... 잘 작동 : 내가 당신의 코멘트에서 제대로 이해하는 경우가 제출 버튼을 클릭하면 는 페이지가 변경하고 해당 돼요 ... 그게 있다면, 다음 그냥이

onClick="sendemail();return false;" 
에 제출 버튼에 onClick 속성을 변경

또는 입력 사항을 입력 부로 변경하십시오. tton ... 그 이유는 제출 버튼을 클릭하면 onClick 이벤트가 있어도 양식이 발송되므로 return false은 중지해야합니다 ... 기본 이벤트를 막으려 고 할 때 링크와 동일합니다

행운을 빌어 요