+ -
当前位置:首页 → 问答吧 → ajax post 怎样设置 同步 async:false

ajax post 怎样设置 同步 async:false

时间:2011-09-11

来源:互联网

//$.post()方式:  
  $('#test_post').mousedown(function (){  
  $.post(  
  'login.php',  
  {  
  username:$('#username').val(),  
  password:$('#password').val() 
  },  
  function (data) //回传函数  
  {  
  var myjson='';  
  eval('myjson=' + data + ';');  
  $('#result').html("姓名1:" + myjson.username + "<br/>密码1:" + myjson.password);  
  }  
  );  
  }); 


async:fals写在哪里?怎样写

作者: mikemeego002   发布时间: 2011-09-11

参考:http://af8991.iteye.com/blog/1141019
Ajax请求默认的都是异步的
如果想同步 async设置为false就可以(默认是true)
JScript code

var html = $.ajax({
  url: "some.php",
  async: false
}).responseText;


或者在全局设置Ajax属性
JScript code
$.ajaxSetup({
  async: false
  });

再用post,get就是同步的了

作者: zswang   发布时间: 2011-09-11