ajax实例入门代码

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了ajax实例入门代码脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

静态页面

复制代码 代码如下:

<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="jquery/jquery.js" >
//这里不可以用<script type="" src="" />
</script>
<script type="text/javascript">
/*
encodeURI 方法
对URL传递的参数进行编码
将文本字符串编码为一个有效的统一标识符 (URI)。
*/
function createQueryString(){
VAR FirstName=encodeURI($("#firstName").val());
var birthday=encodeURI($("#birthday").val());
//组合成对象的形式
var queryString={firstName:firstName,birthday:birthday};
return queryString;
}
function doRequestUsingGET(){
$.get("AjaxServe.aspx",createQueryString(),
//发送GET请求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
function doRequestUsingPOST(){
$.post("AjaxServe.aspx",createQueryString(),
//发送POST请求
function(data){
$("#serverResponse").html(decodeURI(data));
}
);
}
</script>
</head>
<body>
<h2>输入姓名和生日</h2>
<form>
<input type="text" id="firstName" /><br />
<input type="text" id="birthday" />

<input type="button" value="GET" onclick="doRequestUsingGET();" /><br />
<input type="button" value="POST" onclick="doRequestUsingPOST();" />
</form>
<div id="serverResponse"></div>
</body>
</html>


动态页面
复制代码 代码如下:

PRotected void Page_Load(object sender, Eventargs e)
{
//Response.Write("后台数据");
if (Request.HttpMethod == "POST")
Response.Write("POST:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
else if(Request.HttpMethod=="GET")
Response.Write("GET:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
}

脚本宝典总结

以上是脚本宝典为你收集整理的ajax实例入门代码全部内容,希望文章能够帮你解决ajax实例入门代码所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。