我这个ajax对象,怎么responseText属性为空呢?
我打印 myajax 的时候,看到 responseText 有值.
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script src="/jquery.min.js"></script>
<title>02.ajax传值到服务器,ajax内接收值</title>
<script>
$(function(){ /***加载事件的开始,这行就不别改了!**/
myajax = $.ajax
(
{
data:'name=yb&sex=nan',
type : 'POST', //默认是GET
url : 'http://localhost/YB-JavaScript/jQueryajax/03.php',
}
);
console.log( myajax );
$("div").html(myajax.responseText);
alert( myajax.responseText);
}) /***加载事件的结束,这行就不别改了!**/
</script>
</head>
<body>
<div></div>
<body>
console.log 的时候,明明有:
因为AJAX 是异步的,你打印responseText 时AJAX 请求还没完成,所以responseText 是空的。
改成: