2010-12-02 7 views
2

this one과 같은 내 페이지에서 "Have have"버튼을 클릭하면 양식이 jQuery Tools 오버레이를 통해 표시됩니다. 양식을 작성하고 PHP 스크립트 (로컬 스크립트)에 제출 한 다음 유효성을 검사하고 제출하면 서버의 응답에 따라 감사 또는 오류 메시지가 나타납니다. FF, 사파리 및 오페라에서 훌륭하게 작동하지만 IE 또는 Chrome에서는 작동하지 않습니다. IE와 Chrome은 .ajax가 스크립트 URL이있는 빈 페이지에서 찾는 리턴 메시지를 출력합니다. 내 크로스 도메인 cURL ajax 스크립팅이 작동하지만이 기능이 없기 때문에 뭔가 잘못되어 있어야합니다! 여기에 코드jQuery .ajax가 IE 및 Chrome에서 작동하지 않습니다.

$(document).click(function() { 
     $.validator.methods.equal = function(value, element, param) { 
     return value == param; 
    }; 
    var validator = $("#request").bind("invalid-form.validate", function() { 
      $("#summary").html("Your form contains " + validator.numberOfInvalids() + " error(s), please fix."); 
     }).validate({ 
      //debug: true, 
      errorElement: "em", 
      errorContainer: $("#summary"), 
      errorPlacement: function(error, element) { 
       error.appendTo(element.parent("li")); 
      }, 
      success: function(label) { 
       label.text("ok!").addClass("success"); 
      }, 
      submitHandler: function(form) { 
       $("#processing").show(); 
      var dataString = $(form).serialize(); 
       $.ajax({ 
       type: $("#request").attr('method'), 
       url: form.action, 
       data: dataString, 
       clearForm: true, 
       success: function(data) { 
        if (data=="SuccessMail Sent") { 
         $("#formWrap, #supportHdln").hide(); 
          $("#thankYou").html('<h2><span>Thank You</span> We have received your request.</h2><p>A Customer Service Representative from NinjaTrader will contact you shortly.</p>').fadeIn("slow"); 
         } else { 
          $("#formWrap, #supportHdln").hide(); 
          $("#error").html('<h2><span>Uh Oh</span> We are unable to process your request.</h2><p>Please make sure all fields were filled out correctly. If you are still having trouble, please <a href=\"mailto:[email protected]?subject=Support Email\">email us</a></p>').fadeIn("slow"); 
        } 
        } 
       }); 
      return false; 

      }, 
      rules: { 
        hs_customer_firstname: { 
        required: true, 
        minlength: 2 
       }, 
        hs_customer_lastname: { 
        required: true, 
        minlength: 2 
       }, 
        hs_customer_email: { 
        required: true, 
        email: true 
       }, 
        confirmEmail: { 
        required: true, 
        email: true, 
        equalTo: "#hs_customer_email" 
       }, 
        hs_customer_phone: { 
        required: false, 
        digits: true 
       }, 
        hs_category: { 
        required: true  
       }, 
        hs_customLargeTextField: { 
        required: true, 
        minlength: 20 
       }, 
        math: { 
        required: true, 
        equal: <?php echo $randomNumTotal; ?> 
       } 
      }, 

      messages: { 
       hs_customer_firstname: { 
        required: "Please Enter Your First Name", 
        minlength: "Your First Name Must be at Least 2 Characters" 
       }, 
       hs_customer_lastname: { 
        required: "Please Enter Your Last Name", 
        minlength: "Your Last Name Must be at Leaset 2 Characters" 
       }, 
       hs_customer_email: { 
        required: "Please enter your email address", 
        email: "Please enter a valid email address" 
       }, 
       confirmEmail: { 
        required: "Please Confirm Your Email Address", 
        email: "Please Enter a Valid Email Address", 
        equalTo: "Please Enter the Same Email Address as Above" 
       }, 
       hs_customer_phone: { 
        digits: "Numbers only" 
       }, 

       hs_category: { 
        required: "Please Select a Category" 
       }, 
       hs_customLargeTextField: { 
        required: "Please Leave a Comment", 
        minlength: "Your comment must be at least 20 characters" 
       }, 
       math: { 
        required: "Please Solve the Problem", 
        equal: "Please Solve the Problem Correctly" 
       } 
      } 
     }); 
    }); 

이며, 여기가

그것은 임의의 숫자 유효성 검사해야했다
<?php 

if(empty($_POST['hs_customer_firstname']) || empty($_POST['hs_customer_lastname']) || 
empty($_POST['hs_customer_email']) || empty($_POST['hs_category']) || 
empty($_POST['hs_customLargeTextField']) || empty($_POST['math'])) { 
echo ('Success'); 
} 

$headers = 'From: [email protected]' . "\r\n" . 
     'Reply-To: [email protected]' . "\r\n" . 

$firstname = $_POST['hs_customer_firstname'] ; 
//more like this 

mail("[email protected]", "Support Request", 
//$_POST fields 
"From: $email"); 
if(mail($firstname, $lastname, $email, $category, $inquiry)) { 
echo ('Mail Sent'); 
} else { 
echo ('Error: Mail failed'); 
} 

?> 
+0

요청을 보려면 콘솔의 네트워크 탭을 확인하십시오. – methodin

+0

예, 예상 메시지를 표시합니다! 그게 뭐야. –

+0

@Dirty Bird Design : AJAX를 통해 양식을 제출하기 전에 양식의 기본 동작을 취소 하시겠습니까? event.preventDefault() (jQuery)를 잊어 버렸을 때 이상한 행동을 보았다. 나는 이것이 b/c 일어나고 있는지 말할 수 없다. 나는 당신이 폼에 submit 이벤트를 연결하는 곳을 보지 못했다. –

답변

0

, IE와 크롬은 JS 코드에서 좋아하지 않았다 실행하는 작은 PHP 스크립트입니다. 일단 내가 그것을 없애고 양식 페이지에서 오버레이와 함께 가져온 유효성 검사를 제거, 그것을 작동 별도의 JS 파일로 부모 페이지에 추가되었습니다. 왜 random num total이 작동하지 않는 지 잘 모르겠다. 부모 페이지에 PHP 함수를 추가했을 때 유효성 검사에서 JS 오류가 발생하지 않았지만 숫자를 올바르게 추가했을 때 유효성을 검사하지 못했습니다. 오 잘, 어떤 것을 잃어 버려라.

관련 문제