jquery ajax php
HTML+JQ
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="js/jquery-1.8.2.min.js"></script>
</head>
<style>
*{margin:0px;padding:0px;}
.pic_mrt{ width:520px; height:350px;}
#load{ display:none}
</style>
<body>
姓名:<input type="text" name=‘name‘ id="name"><br />
性别:男<input type="radio" name=‘sex‘ id="sex" value="man"> 女<input value="girl"type="radio" name=‘sex‘ id="sex"><br />
出生年份:<select name="year" id="year">
<option value="1989">1989</option>
<option value="1980">1980</option>
<option value="1981">1981</option>
<option value="1982">1982</option>
</select>
<br />
爱好:吃<input type="checkbox" name="like" value="eat">睡<input type="checkbox" name="like" value="sleep">玩<input value="play" type="checkbox" name="like"><br />
<input type="submit" id="submit"> <img src="images/2.gif" id="load"><p></p>
<script>
var arr = new Array();
$("#submit").click(function(){
check_black();
var mrt = {name:$(‘#name‘).val(),
sex:$("input[name=‘sex‘]:checked").val(),
year:$(‘#year‘).val(),
like:arr};
$.ajax({
url: "sql.php",
type: "POST",
data:mrt,
beforeSend: function(){
$(‘#load‘).css(‘display‘,‘inlineBlock‘);
},
complete: function(){
$(‘#load‘).css(‘display‘,‘none‘);
},
error: function(){
alert(‘Error loading XML document‘);
},
success: function(data){
data = JSON.parse(data);
$("p li").remove();
for(var key in data){
$("p").append("<li>"+data[key]+"</li>");
}
}
});
})
function check_black(){
var blackName = document.getElementsByName("like");
for(var i = 0; i < blackName.length; i++)
{
if(blackName[i].checked == true)
{
arr[i]= blackName[i].value;
}
}
}
</script>
</body>
</html>
PHP
<?
header(‘Content-Type:text/html;charset=GB2312‘);
$backValue=array();
$backValue[0]=$_POST[‘name‘];
$backValue[2]=$_POST[‘sex‘];
$backValue[3]=$_POST[‘year‘];
$backValue[4]=$_POST[‘like‘];
$code = json_encode($backValue);
$code = preg_replace("#\\\u([0-9a-f]+)#ie", "iconv(‘UCS-2‘,‘GB2312‘, pack(‘H4‘, ‘\\1‘))", $code);
echo $code;
/*
function digui($arr) {
if (is_array($arr)) {
foreach ($arr as $v) {
if (is_array($v)) {
digui($v);
} else {
echo $v;
}
}
}
}
digui($backValue);
*/
?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。