jquery ajax 的 $.get()用法詳解


js文件

$(document).ready(function(){
	$("form").submit(function(event) {event.preventDefault()})//取消submit的默認行為
	$("form input[type='submit']").click(function(){
	    var url = $('form').attr('action'); // 取Form中要提交的鏈接
	    var param = {}; // 組裝發送參數
	    param['name']  = $('form input[name=name]').val();
	    param['age'] = $('form input[name=age]').val();
	  $.get(url, param, function(dom) { $('div.get').append(dom) }) ;  // 發送並顯示返回內容
	});
})

html文件

<form action="ajax.php" method="get">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
<div class="get">這是ajax的get方法</div>

php文件

error_reporting(0);

  if($_GET["name"]=="kitty")
{
	
	$name= "you are the lucky";
}
else 
$name=$_GET["name"];
$age=$_GET["age"];
echo "<div>	".$name."	".$age."</div>";

總結


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM