向書本學(xué)習(xí),還要向?qū)嵺`學(xué)習(xí)、向生活學(xué)習(xí)。消化已有知識(shí),
而且要力求有所發(fā)現(xiàn)、有所發(fā)明、有所創(chuàng)造
2019/3/14 8:48:36
們要達(dá)到的目的是點(diǎn)擊按鈕,獲得服務(wù)器的當(dāng)前時(shí)間,aspx的html如下:
Html
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Linkedu.Web.WebWWW.Default" %>
<!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 runat="server">
<title>測(cè)試</title>
<script language="javascript" src="javascript/prototype/extras-array.js"></script>
<script language="javascript" src="javascript/xmlHttp.js"></script>
<script language="javascript" src="javascript/eventRouter.js"></script>
<script language="javascript" src="Default.js"></script>
<script language="javascript">
</script>
</head>
<body>
<form id="form1" runat="server">
用Post方式獲得服務(wù)器的當(dāng)前時(shí)間
<input id="btnTestPost" type="button" value="Post" />
用Get方式獲得服務(wù)器的當(dāng)前時(shí)間
<input id="btnTestGet" type="button" value="Get" />
<div id="divResult"></div>
</form>
</body>
</html>
要用javascript 發(fā)送xmlHttp 請(qǐng)求必須解決的問題是跨瀏覽器的支持。我們把xmlHttp的發(fā)送封裝在一個(gè)javascript對(duì)象中,同時(shí)在這個(gè)對(duì)象中解決了跨瀏覽器支持的問題。代碼如下:
xmlHttp對(duì)象
/**//*
url-loading object and a request queue built on top of it
*/
/**//* namespacing object */
var net=new Object();
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;
/**//*--- content loader object for cross-browser requests ---*/
net.xmlHttp=function(url, onload, params, method, contentType, onerror){
this.req=null;
this.onload=onload;
this.onerror=(onerror) ? onerror : this.defaultError;
if(typeof(method) == "undefined" || method == null)
{
method = "POST";
}
this.loadXMLDoc(url, params, method, contentType);
}
net.xmlHttp.prototype.loadXMLDoc=function(url, params, method, contentType){
if (!method){
method="GET";
}
if (!contentType && method=="POST"){
contentType='application/x-www-form-urlencoded';
}
if (window.XmlHttpRequest){
this.req=new XmlHttpRequest();
} else if (window.ActiveXObject){
this.req=new ActiveXObject("Microsoft.xmlHttp");
}
if (this.req){
try{
var loader=this;
this.req.onreadystatechange=function(){
net.xmlHttp.onReadyState.call(loader);
}
this.req.open(method,url,true);
&nb
深圳市南山區(qū)南山街道南海大道西桂廟路北陽光華藝大廈1棟4F、4G-04
咨詢電話:136 8237 6272
大客戶咨詢:139 0290 5075
業(yè)務(wù)QQ:195006118
技術(shù)QQ:179981967
客戶案列
新聞資訊
資質(zhì)榮譽(yù)
團(tuán)隊(duì)風(fēng)采
項(xiàng)目進(jìn)度查詢
售前QQ咨詢
QQ溝通 項(xiàng)目QQ溝通