php中實作ajax提交form表單的方法:1、建立一個HTML和PHP檔案並建立form表單;2、透過「$.ajax({type: "post",url:"text7.php ",data:dataString...})」代碼提交表單即可。
本文操作環境:Windows7系統、PHP7.1、Dell G3電腦。
php中怎麼實作ajax提交form表單?
透過php jq ajax提交form表單
程式碼如下:
html
<div id="contact_form"> <form name="contact" method="post" > <label for="name" id="name_label">姓名</label> <input type="text" name="name" id="name" size="30" value="" class="text-input" /> <label class="error" for="name" id="name_error">此项必填</label> <label for="email" id="email_label">您的Email</label> <input type="text" name="email" id="email" size="30" value="" class="text-input" /> <label class="error" for="email" id="email_error">此项必填</label> <label for="phone" id="phone_label">您的联系电话</label> <input type="text" name="phone" id="phone" size="30" value="" class="text-input" /> <label class="error" for="phone" id="phone_error">此项必填</label> <br /> <input type="button" name="submit" class="button" id="submit_btn" value="我要发送" /> </form> </div>
js
<script language="javascript"> $(function(){ $(".error").hide(); $(".button").click(function(){ var name= $("#name").val(); if(name==""){ $("#name_error").show(3600); $("#name_error").focus(); return false; //return false 的作用是为了让input框效果是一次只出现一个 //当type为submit的时候,不return false 的话就会提交form表单而没有效果 //当type为button的时候,不用return false也可以显示效果 //原话:而只有当出现错误,即为空时,错误才会出现,因为有 return false 的作用,每次仅会出现一个错误。 } var email= $("#email").val(); if(email==""){ $("#email_error").show(3600); $("#email_error").focus(); return false; } var phone= $("#phone").val(); if(phone==""){ $("#phone_error").show(3600); $("#email_error").focus(); return false; } var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone; //document.write(dataString); $.ajax({ type: "post", url:"text7.php", data:dataString, success:function(mag){ // alert(mag);return; //ajax提交form表单php里无法看post值,只能在回调函数里面打印,下面为成功之后的返回效果 $('#contact_form').html("<div id='message'></div>"); $("#message").html("<p>联系方式已成功提交!</p>") .append("<p>Script design</p>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='yes.ico' / alt="php中怎麼實作ajax提交form表單" >"); }); } }) return false; }) }) </script>
#php
print_r($_POST); echo $_POST['name'].'<br>'."i'm ok!~";die;
推薦學習:《PHP影片教學》
以上是php中怎麼實作ajax提交form表單的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文比較了酸和基本數據庫模型,詳細介紹了它們的特徵和適當的用例。酸優先確定數據完整性和一致性,適合財務和電子商務應用程序,而基礎則側重於可用性和

本文討論了確保PHP文件上傳的確保,以防止諸如代碼注入之類的漏洞。它專注於文件類型驗證,安全存儲和錯誤處理以增強應用程序安全性。

本文討論了在PHP中實施API速率限制的策略,包括諸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之類的庫。它還涵蓋監視,動態調整速率限制和手

本文討論了使用password_hash和pyspasswify在PHP中使用密碼的好處。主要論點是,這些功能通過自動鹽,強大的哈希算法和SECH來增強密碼保護

本文討論了OWASP在PHP和緩解策略中的十大漏洞。關鍵問題包括注射,驗證損壞和XSS,並提供用於監視和保護PHP應用程序的推薦工具。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)