jquery $.ajax() 应用中的一点困惑,望高手点拨
-----------------------------------
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/Javascript">
$(document).ready(function(){
$(".ajax_btn").click(function(){
$.ajax({
type:"POST",
url:"test2.php",
data:"name=12345",
success:function(data){
alert( data);
}
});
})
})
</script>
</head>
<body>
<button class="ajax_btn">clickme</button>
</body>
</html>
---------------
test2.php文件内容
-----------------
<?php
$name=$_POST["name"];
echo $name;
?>
--------------------
调试的内容
=================(Request-Line) POST /php/jobass/test2.php HTTP/1.1
Accept */*
Accept-Encoding gzip, deflate
Accept-Language zh-CN
Cache-Control no-cache
Connection Keep-Alive
Content-Length 0
Content-Type application/x-www-form-urlencoded; charset=UTF-8
DNT 1
Host localhost
Referer http://localhost/php/jobass/test.php
User-Agent Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
X-Requested-With XMLHttpRequest
=================================================
问题在于,我用POST方式时候,弹出的ALERT对话框值为空,而用GET却能正确显示12345。这让我很困惑,求解惑。
相关推荐
jQuery Ajax之$.get()方法和$.post()方法
注意:$.get()和$.post()方法是jQuery中的全局函数。前面讲到的load()方式是对jQuery对象进行操作的。 1、 $.get()方法 $.get()方法使用GET方式来进行异步请求。 它的语法结构为: $.get( url [, data] [, callback] [, type] ) $.get()方法参数解释如下表: 参数名称 类 型 说 明 url String 请求的HTML页的URL地址 data(可选) Object 发送至服务器的key/value数据会作为QueryString附加到请求URL中 callback(可选)
Jquery中$.ajax()方法参数详解
俗说好记性不如个烂笔头,下面是jquery中的ajax方法参数详解,这里整理了一些供大家参考。 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址。 2.type: 要求为String类型的参数,请求方式(post或get)默认为get。注意其他http请求方法,例如put和delete也可以使用,但仅部分浏览器支持。 3.timeout: 要求为Number类型的参数,设置请求超时时间(毫秒)。此设置将覆盖$.ajaxSetup()方法的全局设置。 4.async: 要求为Boolean类型的参数,默认设置为true,所有请求均为异步请求。如果需要发送同步请求,
学习jQuery中的Ajax——$.get()方法
NULL 博文链接:https://xa-zbl.iteye.com/blog/552797
JQuery中$.ajax()方法参数详解及应用
JQuery中$.ajax()方法想必大家并不陌生吧,在本文将为大家介绍下其参数及应用示例,感兴趣的朋友不要错过
jquery 异步调用$.ajax() $.post() $.get()
NULL 博文链接:https://andy2019.iteye.com/blog/1515064


