2017-12-02 1 views
0

電子メール検証サービスに対して電子メールを検証する必要があります。jQuery remoteが電子メール検証サービスに対して有効であること

問題は、私はサービスphpの制御がありません。 サービスは「有効」および「無効」応答を返します。

私が知る限り、jQueryの検証ではtrueまたはfalseを求めています。

リモートURLはhttp://i2srv.com/validate/

例である:それは、この形式で送信する必要があるhttp://i2srv.com/validate/[email protected]

これは私が試みたものです。ディープ延長デフォルト(dataType:"json", data:{nameOfTheElement:valueOfTheElement})remoteメソッドのドキュメントごとにオプションとして

remote: {  
    url: "http://i2srv.com/validate/", 
    type: "post", 
    complete: function(data) { 
     if(data.responseText == "valid") { 
      alert("Email is OK"); 
     } 
    } 
} 

答えて

0

。指定したオプションはデフォルトを上書きします。

そして最も重要な

サーバサイドリソースがjQuery.ajax(XMLHttpRequestを)を介して呼び出され がGETとして検証 要素とその値の名前に対応するキー/値のペアを取得していますパラメータ。

ので、あなたがpostメソッドを使用する必要はありません、ただdataType

remote: { 
     url: "https://i2srv.com/validate/", 
     dataType: 'html', 
     complete: function(data) { 
     if (data.responseText == "valid") { 
      alert("Email is OK"); 
     } 
     } 
    } 

htmlには変更は

$(document).ready(function() { 
 
    $("#signupform").validate({ 
 
    rules: { 
 
     firstname: "required", 
 
     lastname: "required", 
 
     email: { 
 
     required: true, 
 
     email: true, 
 
     remote: { 
 
      url: "https://i2srv.com/validate/", 
 
      dataType: 'html', 
 
      complete: function(data) { 
 
      if (data.responseText == "valid") { 
 
       alert("Email is OK"); 
 
      } 
 
      } 
 
     } 
 
     } 
 
    }, 
 
    messages: { 
 
     firstname: "please enter firstname", 
 
     lastname: "please enter firstname", 
 
    } 
 
    }); 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script> 
 
<div id="signupwrap"> 
 
    <form id="signupform" autocomplete="off" method="get" action=""> 
 
    <table> 
 
     <tr> 
 
     <td class="label"> 
 
      <label id="lfirstname" for="firstname">First Name</label> 
 
     </td> 
 
     <td class="field"> 
 
      <input id="firstname" name="firstname" type="text" value="" maxlength="100"> 
 
     </td> 
 
     <td class="status"></td> 
 
     </tr> 
 
     <tr> 
 
     <td class="label"> 
 
      <label id="llastname" for="lastname">Last Name</label> 
 
     </td> 
 
     <td class="field"> 
 
      <input id="lastname" name="lastname" type="text" value="" maxlength="100"> 
 
     </td> 
 
     <td class="status"></td> 
 
     </tr> 
 

 
     <tr> 
 
     <td class="label"> 
 
      <label id="lemail" for="email">Email Address</label> 
 
     </td> 
 
     <td class="field"> 
 
      <input id="email" name="email" type="text" value="" maxlength="150"> 
 
     </td> 
 
     <td class="status"></td> 
 
     </tr> 
 

 
     <tr> 
 
     <td class="label"> 
 
      <label id="lsignupsubmit" for="signupsubmit">Signup</label> 
 
     </td> 
 
     <td class="field" colspan="2"> 
 
      <input id="signupsubmit" name="signup" type="submit" value="Signup"> 
 
     </td> 
 
     </tr> 
 
    </table> 
 
    </form>

+0

グレート下記のデモをご覧ください!私は今遠隔地からの応答を得ています。 常に妥当性は検証されない(常にエラーです)。電子メールが有効かどうかに応じて、「有効」または「無効」というエラーメッセージが表示されます。 – user2767441

+0

あなたが上記のデモを使用して、それがあなたに有効であると指定したものと同じ電子メールを提供すれば '警告は'電子メールはOKです 'ということです、つまり、あなたはあなたのスクリプトで応答を得ていない上記のコードと慎重に比較してください。ユーザーの 'skyhawk133 @ gmail.com'を電子メールの中の上記の形で入力してください。 –

+0

と答えが正しいかどうかは、@ user2767441 –

関連する問題