2017-02-24 8 views
1

データベースにデータを保存するクラスとその関数を含むphpファイルを呼び出しています。 コールはajax経由です。 mozillaですべてうまく動作します。&はクロムに含まれていません。 しかし、非常に驚​​くべきことは突然何度か動作します。&もう一度や他の時間を試してみると失敗します。 私は完璧なPHPファイルを確認しています。 はさえ、Ajaxコードが正しく実行されることの後にあまりにも...Ajaxリクエストはmozillaで完璧に動作し、クロムでは動作しません(時には機能するため、非常に混乱します)。

$('#quick_contact').validate({ 
     rules: { 
      qc_name: { 
       required: true, 
       minlength: 0 
      }, 
      qc_email: { 
       required: true, 
       email: true 
      }, 
      qc_msg: { 
       required: false, 
       minlength: 0 
      } 
     }, 
     messages: { 
      name: { 
       required: "Enter Your Name", 

      }, 
      email: { 
       required: "Please Enter Your e-mail" 
      }, 
      message: { 
       required: "Please Enter Message" 
      } 
     }, 
     submitHandler: function(form) { 
      $.ajax({ 
       type:"POST", 
       url:root_path+"db_contact_forms/contact_forms.php", 
       data: $(form).serialize(), 
       dataType: "json", 
       async: false, 
       success: function(dres) { 
        alert(dres.status); 
       }, 
       error: function(textStatus, errorThrown) { 
        alert(errorThrown); 
       } 
      }); 
     } 

    }); 

だからクロームでその初めて&のための解析エラーなどのエラーを投げます。私は混乱しています。

PHP:

<?php 
if(isset($_POST["qc_submit"])) 
{ 
    $contact_form = new contact_forms(); 
    $contact_form->save(); 
    echo '{"status":1}'; 
} 


class contact_forms 
{ 
    public $con; 
    public function __construct() 
    { 
     $this->con = mysqli_connect("localhost", "root", "", "orione_db"); 
     if(!$this->con) 
     { 
      echo "Not Connected"; 
     } 
    } 

    function save() 
    { 
      $sql="insert into quick_contact_form(name, email, msg, datetime) values('".$_POST["qc_name"]."','".$_POST["qc_email"]."','".$_POST["qc_msg"]."', '".date('d-m-Y h:i:s')."')"; 

      mysqli_query($this->con, $sql); 

    } 


} 

?> 

HTML:

<form method="post" id="quick_contact" novalidate="novalidate"> 
    <input type="text" class="form-control" id="name" name="qc_name" placeholder="Name"> 

    <input type="email" class="form-control" id="email2" name="qc_email" placeholder="Email" style="margin-top:10px;"> 

    <textarea class="form-control" rows="6" id="message" name="qc_msg" placeholder="Message" style="height: 134px;margin-top: 10px;"></textarea> 

    <div class="row m0"> 
    <button type="submit" name="qc_submit" class="btn btn-default submit"><strong>Submit Now</strong><i class="fa fa-angle-double-right" style="padding-left:6px;"></i></button> 

    </div> 
    </form> 

間違っているのでしょうか?誰かが助けてくれることを願っています

+0

コンソールでエラーが発生しましたか? –

+0

応答に何も表示されませんが、クロムではエラーになりません。 –

+0

[これをチェック](http://stackoverflow.com/questions/40545107/jquery-ajax-works-in-chrome-but-not-in-firefox-or-safari)、[this](http:// stackoverflow .com/questions/18274383/ajax-post-working-in-chrome-but-in-firefox)、[this(http://stackoverflow.com/questions/11199685/ajax-works-on-firefox- but-not-chrome)と[this](http://stackoverflow.com/questions/33766900/ajax-works-in-firefox-but-not-in-chrome)を参照してください。多分それがあなたを助けます。 – Condorcho

答えて

4

jQueryのserializeには送信ボタンは含まれていません。また、送信ボタンが設定されていないときには出力がないので、リクエストはjsonを期待しますが、何も取得せず、解析エラーを出します。

関連する問題