Javascript 总结

创建HttpRequest对象:
   var httpRequest;

function createXMLHttpRequest() {
            if(window.XMLHttpRequest)
            {
                httpRequest = new XMLHttpRequest();
            }
            else if(window.ActiveXObject)            
            {
                httpRequest = new ActiveXObject("Microsoft.XMLHttp");
            }
}

通过ajax发送Action URL:
function seacherdata() {
createXMLHttpRequest();
if (httpRequest) {
var data = document.getElementById("seachervalue");
var selects = document.getElementById("seacherwords");
var keywords = selects.options[selects.options.selectedIndex].value;
var url = "seacherdata.do?text=" + data.value+"&keywords="+keywords;
httpRequest.open("POST",url,true);
httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
httpRequest.onreadystatechange = function() {
if(httpRequest.readyState == 4 && httpRequest.status == 200) {
var result = httpRequest.responseText;
document.parentWindow.parent.document.getElementById("mainframe").src=result;
}
}
httpRequest.send(null);
}
}

httpRequest.responseText得到的字符串是:
PrintWriter writer = response.getWriter();
writer.print("ok");
得到的字符串就是"ok"/.

你可能感兴趣的:(JavaScript,Ajax,Microsoft)