当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 学习Ajax教程,详细了解Get与Post

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 学习Ajax教程,详细了解Get与Post


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 367 ::
收藏到网摘: n/a

学习Ajax教程,详细了解Get与Post

Get方式:
作用:可传送简单数据
大小:url最大长度是2083 bytes,可以用于GET传递数据的长度是2048 bytes
包含体:数据追加到url中发送,也就是http的header传送

Post方式:
作用:可传送简单复杂数据
大小:web.config里限制
包含体:数据在http请求的实体内容里传送

Ajax用Post模式传送数据.需注意:
1.设置header的Context-Type为application/x-www-form-urlencode确保服务器知道实体中有参数变量.通常使用XmlHttpRequest对象的SetRequestHeader("Context-Type","application/x-www-form-urlencoded;")
2.参数是名/值一一对应的键值对,每对值用&号隔开.如 name=abc&sex=man&age=18.
3.参数在Send(参数)方法中发送
4.服务器端请求参数区分Get与Post.例如asp.net中以Request.Form["name"]对实体中的参数请求.这时url参数请求Request.QueryString["name"]将引发异常

<javascript language="javascript>
function StateEvent()
{
if(XmlHttpObject.readyState == 4)
{
if(XmlHttpObject.status == 200)
{
//code
}
}
}

function CreateXmlHttp()
{
if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
return new XmlHttpRequest();
}
}

function Start()
{
var ParamString = "name=abc&sex=man&age=18";
var XmlHttpObject = CreateXmlHttp();
XmlHttpObject.onreadystatechange = StateEvent;
XmlHttpObject.open("post","test.aspx",true);
XmlHttpObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //设置服务器响应请求体参数
XmlHttpObject.send(ParamString);
}
</script>