在Web开发中,有时我们希望页面提交但又不刷新当前页,此时可以使用XML HTTP Request object来做处理。
例如如下代码:
< HTML > < HEAD > < TITLE ></ TITLE > < script language = " javascript " > function func_submit() { var xmlhttp; try { xmlhttp = new ActiveXObject( " Msxml2.XMLHTTP " ); } catch (e1) { try { xmlhttp = new ActiveXObject( " Microsoft.XMLHTTP " ); } catch (e2) { alert(e2); } } if (xmlhttp) { xmlhttp.open( " GET " , " test.txt " , true ); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 ) { document.getElementById('content').innerHTML = xmlhttp.responseText; } } xmlhttp.send( null ); } } </ script > </ HEAD > < BODY > < button onClick = " func_submit() " > mysubmit </ button > < div id = " content " ></ div > </ BODY > </ HTML >此时运行代码,点击提交按钮,可以发现在div节点内部把text.txt文件的内容填充进去了。
转载于:https://www.cnblogs.com/hardyfan/articles/192851.html
相关资源:JAVA上百实例源码以及开源项目