Home > Backend Development > PHP Tutorial > 求ajax代码,后台php

求ajax代码,后台php

WBOY
Release: 2016-06-23 13:48:52
Original
900 people have browsed it

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>
Copy after login


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

//表单代码

<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>
Copy after login

//index.php代码

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

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template