---
title: "ajax调用基础公共代码，经过测试！"
author: "genius"
date: "2008-11-18T13:27:38Z"
tags: ["Ajax", "JSP", "Microsoft"]
slug: "ajax"
draft: false
lastmod: "2008-11-18T14:14:27Z"
id: 269348
url: "https://genius.iteye.com/blog/269348"
---

			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"));
     	};