您好,登录后才能下订单哦!
这期内容当中小编将会给大家带来有关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> 
<h3>输入姓名和生日</h3> 
<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入门代码怎么写了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。