AJax_1
发布时间:2020-12-16 02:00:36 所属栏目:百科 来源:网络整理
导读:首先,AJAX就是异步 Javascript和XML的简称 按我现在的理解,局部刷新原理不难,用的就是js的功能 比较核心的是内部用的XmlHttpRequest发送异步请求和回应 一般写简单AJAX有几个步骤,一个是创建XMLHttpRequest对象 然后是相对比较固定的几个句式, xmlhttp.
首先,AJAX就是异步 Javascript和XML的简称 按我现在的理解,局部刷新原理不难,用的就是js的功能 比较核心的是内部用的XmlHttpRequest发送异步请求和回应 一般写简单AJAX有几个步骤,一个是创建XMLHttpRequest对象 然后是相对比较固定的几个句式, xmlhttp.open()用来指定请求的地址,其实就是指定获取数据的来源。 xmlhttp.onreadystatechange用来指定执行的函数 然后就是xmlhttp.send()表示发送请求操作括号中是参数,一般为空就是null。 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.io.*" import="javax.swing.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script type="text/javascript"> var xmlhttp; function loadXMLDoc() { xmlhttp=null; if (window.XMLHttpRequest) {// code for Firefox,Opera,IE7,etc. xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE6,IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change; xmlhttp.open("GET",'ImbaMallLog.txt',true); xmlhttp.send(null); } else { alert("Your browser does not support XMLHTTP."); } } function state_Change() { if (xmlhttp.readyState==4) {// 4 = "loaded" if (xmlhttp.status==200) {// 200 = "OK" document.getElementById('myDiv').innerHTML=xmlhttp.responseText; } else { alert("Problem retrieving data:" + xmlhttp.statusText); } } } </script> </head> <body> This is my JSP page. <br> <% JFileChooser jfc= new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES ); jfc.showDialog(new JLabel(),"选择"); File file=jfc.getSelectedFile(); DataInputStream dis=null; dis=new DataInputStream(new FileInputStream(file)); boolean flag=true; String sss=new String(""); while (flag){ String str=new String(""); str=dis.readLine(); if (str==null){ flag=false; System.out.println("break"); continue; } System.out.println(str); sss+=str; } %> <button type="button" onclick="loadXMLDoc()">click</button> <div id="myDiv"><h2>Let AJAX change this text</h2></div> </body> </html>话说我之前还想用jsp中的java部分通过读取文件来获取文件内容变成一个字符串,然后传到js里面,发现不太对劲,好像不能这样传参的。。。从java部分跳不到js部分 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |