首頁  >  文章  >  後端開發  >  求ajax代码,后台php

求ajax代码,后台php

WBOY
WBOY原創
2016-06-23 13:48:52844瀏覽

form表单内容 name ,age,sex,提交到后台index.php的insert()方法,用post方式。求详细代码,实在是不会呀


回复讨论(解决方案)

建议 LZ  还是仔细学习一下前端的知识

sample.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>	<head>		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />		<title>HTML</title>		<script  src="jquery.js"type="text/javascript"></script>		<script  type="text/javascript">						var data={name:'orange',age:20,sex:'male'};			var url='index.php';						jQuery(document).ready(function(){								jQuery('#submit').click(									function(){						jQuery.post(url,data,function(result){										if(result.code==0){							alert('插入成功');						}else{							alert('插入失败,错误信息:'+result.msg);						}												},'json').error(function(){							alert("网络不通或者服务器执行失败");						});					}				);				});		</script>			</head>    <body>		<input type="button"  id="submit" value="提交" />	</body></html>


index.php
<?php		function insert(){				$ret = array('code'=>1,'msg'=>'数据不合法');				extract($_POST);		/*		* 执行逻辑		* 插入数据库 $name $age $sex		*/		$ret['code'] = 1;				echo json_encode($ret);	}				insert();

//表单代码

<form action="index.php" method="post">   姓名:<input type="text" name="name" /><br />   年龄:<input type="text" name="age" /><br />   性别:<input type="text" name="sex" /><br />   <input type="submit" value="提交" /></form>

//index.php代码

$name=$_POST['name'];$age=$_POST['age'];$sex=$_POST['sex'];  function insert($name,$age,$sex){     echo $name.$age.$sex;  }insert($name,$age,$sex);

好吧,有这么多,我就不提交了。。。多学习吧。网上很多资料

我也在学JQ,用JQ得到要提交的值,在拼装。提交到服务端处理和普通程序一样。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn