Blogger Information
Blog 37
fans 0
comment 0
visits 21189
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
前端第十八课:javascript基础7-PHP培训九期线上班
渡劫小能手
Original
466 people have browsed it

$.post

向指定的资源提交要处理的数据
$.post( url, [ data ], [ success ], [ dataType ] )
第一个参数是请求到哪个页面,第二个参数是传递的数据,第三个是请求成功后怎么处理后台返回的数据,以什么格式处理后台返回的数据。
function里面的res随便写

  1. var _username = $.trim($('input[name="username"]').val());
  2. var _pwd = $.trim($('input[name="pwd"]').val());
  3. $.post('/dologin.php',{username:_username,pwd:_pwd},function(res){
  4. alert(res.msg);
  5. if(res.code==0){
  6. //window.location.href = "/home.html";
  7. window.location.reload();
  8. }
  9. },'json');
  1. $username = $_POST['username'];
  2. $pwd = $_POST['pwd'];
  3. if($username!='admin'){
  4. $data = json_encode(array('code'=>1,'msg'=>'用户名错误'));
  5. exit($data);
  6. }
  7. if($pwd!='123456'){
  8. $data = json_encode(array('code'=>1,'msg'=>'password error!'));
  9. exit($data);
  10. }
  11. $data = json_encode(array('code'=>0,'msg'=>'登录成功'));
  12. exit($data);

$.get

从指定的资源请求数据

  1. function city() {
  2. $.get('getcity.php',function (re) {
  3. var html = '';
  4. $.each(re.data,function (i,v) {
  5. console.log(v);
  6. html += '<option value="'+v.id+'">'+v.title+'</option>';
  7. });
  8. $('select[name="city"]').html(html);
  9. },'json');
  10. }
  1. <?php
  2. $citys = array(
  3. array('id'=>3,'title'=>'合肥'),
  4. array('id'=>6,'title'=>'黄山'),
  5. array('id'=>7,'title'=>'安庆')
  6. );
  7. $data = json_encode(array('code'=>0,'msg'=>'success','data'=>$citys));
  8. exit($data);

.serialize()

将用作提交的表单元素的值编译成字符串<br />把表单里面的可以提交的数据全部序列化提交

  1. $.post('/dologin.php',$('form').serialize(),function(res){
  2. alert(res.msg);
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:前端的交互数据, 很有用
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post