ITeye博客

ajax调用基础公共代码,经过测试!

genius · 2008-11-18 13:27 · AJAX · Ajax · JSP · Microsoft · Markdown

		try{
			var sync=true;
			var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			
			req.open('POST','index.jsp',!sync);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');   
			req.send("aaa=马新良");				

			function stateChange(){												
				if(req.readyState==4){						
					alert(req.responseText);	
				}
			}	 			
			if(!sync && req.onReadyStateChange) 
				stateChange();
			else
				stateChange();
				
		
		}catch(e){
			alert(e.description);
		}	

下面是取整个send字符串的代码:

BufferedInputStream isr =new BufferedInputStream(request.getInputStream()); byte[] bytes = new byte[(int)request.getContentLength()]; out.println(bytes.length); while(isr.read(bytes)>0){ out.println(new String(bytes,"UTF-8")); };

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。