ajax --XMLHttpRequest

		<script language=javascript>
		
		function newXMLHttpRequest()
			{
				var xmlreq = false;
				if (window.XMLHttpRequest)
				{
					xmlreq = new XMLHttpRequest();
				}
				else if (window.ActiveXObject)
				{
					try
					{
					xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch (e1)
					{
						try
						{        
							xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
						}
						catch (e2)
						{
						alert("Create XMLHttpRequest False!");
						}
					}
				}
				return xmlreq;
			}
			
			function getstr()
			{
			//var xmlhttp=new XMLHttpRequest();
			//var xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			var xmlhttp=newXMLHttpRequest();
			xmlhttp.open("POST", "WebForm4.aspx", true);//xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");   
      xmlhttp.onreadystatechange=function(){

     			 if(4==xmlhttp.readyState&&xmlhttp.status==200)
			 {
                var state = xmlhttp.responseText;
    			alert(state);
			}
			}
			
			xmlhttp.send();
			
		}
		
		
		</script>
	
function addFracasReport() {  
var url="controler?actionId=0_06_03_01&actionFlag=0010";  
var urlmsg="&reportId="+fracasReport1.textReportId.value; //故障报告表编号  
var xmlHttp=Common.createXMLHttpRequest();  
xmlHttp.onreadystatechange = Common.getReadyStateHandler(xmlHttp, eval("turnAnalyPage"));  
xmlHttp.open("POST",url,true);  
xmlHttp.setRequestHeader( " Content-Type " , " application/x-www-form-urlencoded);  
xmlHttp.send(urlmsg);  
}

 

方法 描述 
abort() 停止当前请求 
getAllResponseHeaders() 作为字符串返回完整的headers 
getResponseHeader("headerLabel") 作为字符串返回单个的header标签 
open("method","URL"[,asyncFlag[,"userName"[, "password"]]]) 设置未决的请求的目标 URL,方法,和其他参数 
send(content) 发送请求 
setRequestHeader("label", "value") 设置header并和请求一起发送 


XMLHttpRequest对象的属性:
属性 描述 
onreadystatechange 状态改变的事件触发器 
readyState 对象状态(integer):
0 = 未初始化
1 = 读取中
2 = 已读取
3 = 交互中
4 = 完成 
responseText 服务器进程返回数据的文本版本 
responseXML 服务器进程返回数据的兼容DOM的XML文档对象 
status 服务器返回的状态码, 如:404 = "文件未找到" 、200 ="成功" 
statusText 服务器返回的状态文本信息 

  

 

 ajax页面

<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="WebTestApplication1.WebForm4" %>
<%=str%>

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebTestApplication1
{
	/// <summary>
	/// WebForm4 の概要の説明です。
	/// </summary>
	public class WebForm4 : System.Web.UI.Page
	{
		public string str=string.Empty;
		private void Page_Load(object sender, System.EventArgs e)
		{
			// ページを初期化するユーザー コードをここに挿入します。
			
			str="AAAAAA";
		}

	}
}

 

.config

<httpHandlers>
  <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory,Ajax" />
 
</httpHandlers>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值