JavaScript 阿贾克斯

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 阿贾克斯相关的知识,希望对你有一定的参考价值。

var req;
    
 function backupStory() {
      req = false;

       var title = document.FORM.FIELD.value;
       var content = document.FORM.FIELD.value;
	
      // branch for native XMLHttpRequest object
      if(window.XMLHttpRequest) {
      	try {
  			req = new XMLHttpRequest();
          } catch(e) {
  			req = false;
          }
      // branch for IE/Windows ActiveX version
      } else if(window.ActiveXObject) {
         	try {
          	req = new ActiveXObject("Msxml2.XMLHTTP");
        	} catch(e) {
          	try {
            		req = new ActiveXObject("Microsoft.XMLHTTP");
          	} catch(e) {
            		req = false;
          	}
  	}
}
			
// POST
if(req) {

	var sURL = 'page.asp';

		var params  = 'title='+escape(title)+'&content='+escape(content);
	
    req.open('POST', sURL, true);
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Content-length", params.length);
    req.setRequestHeader("Connection", "close");

    req.onreadystatechange = function() {

    if(req.readyState == 4 && req.status == 200) {
    	    		document.getElementById('').innerHTML = req.responseText;
        	}
        }
        req.send(params);						
    }
}

//GET
if(req) {
  var sURL = 'page.asp?title='+escape(title)+'&content='+escape(content);
	req.open("GET", sURL, true);
  
  req.onreadystatechange = function(){
	
   		if(req.readyState == 4 && req.status == 200)
              document.getElementById('').innerHTML = req.responseText;
  
	}
  	req.send("");
  }
}

以上是关于JavaScript 阿贾克斯的主要内容,如果未能解决你的问题,请参考以下文章

javascript 阿贾克斯

javascript 阿贾克斯

JavaScript 阿贾克斯

AJAX阿贾克斯基础知识

C#-WebForm-AJAX阿贾克斯基本格式

阿贾克斯(AJAX)