html页面:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | < html > < head > < meta http-equiv = "content-type" content = "text/html;charset=utf-8" /> < script type = "text/javascript" src = "jquery-1.8.2.min.js" ></ script > < script type = "text/javascript" > $(function(){ $("#send").click(function(){ var cont = $("input").serialize(); $.ajax({ url:'ab.php', type:'post', dataType:'json', data:cont, success:function(data){ var str = data.username + data.age + data.job; $("#result").html(str); } }); }); }); </ script > </ head > < body > < div id = "result" >一会看显示结果</ div > < form id = "my" action = "" method = "post" > < p >< span >姓名:</ span >< input type = "text" name = "username" /></ p > < p >< span >年龄:</ span >< input type = "text" name = "age" /></ p > < p >< span >工作:</ span >< input type = "text" name = "job" /></ p > </ form > < button id = "send" >提交</ button > </ body > </ html > |
php页面:
1 2 3 4 5 6 7 8 9 | <?php header( "Content-type:text/html;charset=utf-8" ); $username = $_POST [ 'username' ]; $age = $_POST [ 'age' ]; $job = $_POST [ 'job' ]; $json_arr = array ( "username" => $username , "age" => $age , "job" => $job ); $json_obj = json_encode( $json_arr ); echo $json_obj ; ?> |
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
相关文章
php 多维数组筛选判断2020-12-27
Jquery读取json文件并筛选条件的代码2020-12-19
php查询某个表的数据总量代码2020-02-29
php生成静态html分页实现方法2019-12-07
jquery判断字符串中是否包含特定字符的方法2019-07-08
ajax 随机调用json数组显示2019-06-19
php 中返回json 数据实现callback2018-11-18
JQUERY动态插入HTML后不能执行后续JQUERY操作的解决办法2018-11-16
jquery距离底部100象素时层消失2018-11-05
jquery resize屏幕宽度判读语句2018-10-31