JQuery學習(5-AJAX1)

來源:互聯網
上載者:User

標籤:ajax   form   submit   提交表單   

<?php/** 保護AJAX請求的方式*//** 1. 防止表單的自動認可* 對錶單的submit提交進行控制。設定一個全域變數submitError,在進行驗證的方法體中對submitError進行修改;* 若出錯,submitError++; 若錯誤更正submitError--;提交之前,若submitError=0,則進行提交*/?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="jquery-1.5.min.js"></script><style>.pwd{width:200px;height:35px;}</style> <title>無標題文檔</title></head><body><form id="rg_user" ><div><input type="password" size="12" id="rg_pwd" class="pwd" />   <div id="error_info" ></div>    </div>    <input type="submit" /></form><script type="application/javascript">var submtError=0;/** 提交前驗證密碼是否為空白*/$('input[type="submit"]').click(function(){var pwd_length=$('#rg_pwd').val().length;if(pwd_length==0){$('#error_info').html("密碼為空白");submitError++;}if(submitError==0){$('rg_user').submit(function(e){e.preventDefault();//序列化表單資料var formData=$(this).serialize();$.post('php.php',formData,function(data){/*對伺服器返回的資料進行操作*/});});}})</script></body></html>

JQuery學習(5-AJAX1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.