---
title: "Ajax应用1"
author: "shelllgd"
date: "2010-12-07T16:08:11Z"
tags: []
categories: ["Web前端"]
slug: "ajax-1"
draft: false
lastmod: "2010-12-07T16:08:11Z"
id: 835764
url: "https://shelllgd.iteye.com/blog/835764"
---

```java
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

```



```java
var url = "";
url = "jkhtAjaxAction.do?operFlag=checkSave
xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = function handleStateChange() {
if (xmlHttp.readyState == 4) {
	if (xmlHttp.status == 200) {
	                           var value = xmlHttp.responseText;
	  			    }
				}
			};
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
```



```java

response.setContentType("text/html");
response.setHeader("Cathe-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
if ("checkSave".equals(operFlag)) {}
response.getWriter().println(returnflag);
```