php ajax提交数据

来源:互联网 发布:cg软件有哪些 编辑:程序博客网 时间:2024/05/16 11:43
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>test</title><script type="text/javascript" src="js/jquery-1.8.2.min.js"></script></head><body>姓  名:<input type="text" name="txtRealname" id="txtRealname" /> 手机号:<input type="text" name="txtMobile" id="txtMobile" /> 城  市:<input type="text" name="txtAddress" id="txtAddress" /><input type="image" src="images/nbatj.png" name="btnSubmit"id="btnSubmit" value="" /><script type="text/javascript">$("#btnSubmit").bind("click",function(){$.ajax({type:'POST',dataType:'json', //dataType (xml html script json jsonp text)data:{'address':$("#txtAddress").val(),'realname':$("#txtRealname").val(),'mobile':$("#txtMobile").val(),},url:'/index.php?r=nba/Edit',//YII 的生成地址success:function(data) {//成功获得的也是json对象if(data&&data.result&&data.result==1){location.href='/index.php?r=test/view';}else{if(data.message){alert(data.message);}else{alert('保存失败,请稍候再试!');}}},error:function(){                alert('保存失败,请稍候再试!');}});return false;})  </script></body></html>

原创粉丝点击