ajax 返回信息处理实例,ajax的http请求发送函数和处理返回信息函数及实例(The Ajax HTTP requests the sending function and processes ...

ajax的http请求发送函数和处理返回信息函数及实例(The Ajax HTTP requests the sending function and processes the returned information function and instances)

ajax的http请求发送函数和处理返回信息函数及实例(The Ajax HTTP requests the sending function and processes the returned information function and instances)

The definition of XMLHttpRequest / object instance

Var http_request = false;

The definition of HTTP / / reusable function request

Function send_request (method, URL, content, responseType, callback) {// function specifies processing function, initialization, sending a request

Http_request = false;

/ / to initialize the XMLHttpRequest object

If (window.XMLHttpRequest) {//Mozilla browser

Http_request = new (XMLHttpRequest);

If (http_request.overrideMimeType) {// set MiME category

Http_request.overrideMimeType ("text/xml");

}

}

Else if (window.ActiveXObject) {/ / IE browser

{try

Http_request = new ActiveXObject ("Msxml2.XMLHTTP");

Catch (E) {}

{try

Http_request = new ActiveXObject ("Microsoft.XMLHTTP");

Catch (E) {}}

}

}

(if! Http_request) {/ / abnormal, failed to create an object instance

Window.alert ("cannot create a XMLHttpRequest object instance.");

Return false;

}

If (responseType.toLowerCase) (= = text) {

//http_request.onreadystatechange = processTextResponse;

Http_request.onreadystatechange = callback;

}

Else if (responseType.toLowerCase) (= = XML) {

//http_request.onreadystatechange = processXMLResponse;

Http_request.onreadystatechange = callback;

}

{else

Window.alert ("response category parameter error. ");

Return false;

}

The way to determine the URL and / / send the request and asynchronous execution under the code

If (method.toLowerCase) (= = get) {

Http_request.open (method, URL, true);

}

Else if (method.toLowerCase) (= = post) {

Http_request.open (method, URL, true);

Http_request.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");

}

{else

Window.alert ("HTTP request parameter error category. ");

Return false;

}

Http_request.send (content);

}

/ / returns the text format information processing function

Function (processTextResponse) {

If (http_request.readyState = = 4) {/ / object state

If (http_request

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值