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

求ajax代码,后盾php

WBOY
Release: 2016-06-13 12:07:02
Original
964 people have browsed it

求ajax代码,后台php
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"><br /><html><br />	<head><br />		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />		<title>HTML</title><br />		<script  src="jquery.js"type="text/javascript"></script><br />		<script  type="text/javascript"><br />			<br />			var data={name:'orange',age:20,sex:'male'};<br />			var url='index.php';<br />			<br />			jQuery(document).ready(function(){<br />				<br />				jQuery('#submit').click(<br />				<br />					function(){<br />						jQuery.post(url,data,function(result){<br />				<br />						if(result.code==0){<br />							alert('插入成功');<br />						}else{<br />							alert('插入失败,错误信息:'+result.msg);<br />						}<br />						<br />						},'json').error(function(){<br />							alert("网络不通或者服务器执行失败");<br />						});<br />					}<br />				);<br />	<br />			});	<br />	</script>		<br />	</head><br />    <body><br />		<input type="button"  id="submit" value="提交" /><br />	</body><br /></html><br />
Copy after login


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

------解决思路----------------------
//表单代码
<br /><form action="index.php" method="post"><br />   姓名:<input type="text" name="name" /><br /><br />   年龄:<input type="text" name="age" /><br /><br />   性别:<input type="text" name="sex" /><br /><br />   <input type="submit" value="提交" /><br /></form><br />
Copy after login

//index.php代码

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

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

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