---
title: "Ajax使用"
author: "kkllmey"
date: "2008-09-26T15:54:10Z"
tags: []
slug: "ajax"
draft: false
lastmod: "2008-09-26T15:54:10Z"
id: 247123
url: "https://ibc.iteye.com/blog/247123"
---

```
function createXmlHttpRequest() {
 try {
  if (window.ActiveXObject) {
   xmlHttp = new ActiveXObject("msxml2.XMLHTTP");
   return xmlHttp;
  } else {
   return new XmlHttpRequest();
  }
 }
 catch (exception) {
  alert(exception);
  return null;
 }
}

function chSingerType(ob)
{ 
  xmlHttp = createXmlHttpRequest();
  var url = "singer.do?op=doSelectSingerByType&id="+ob.value;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = chSingerTypeResult;
  xmlHttp.send(null);
}
function chSingerTypeResult()
{
 
 if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
   
  var text = xmlHttp.responseText;
  var objs = text.split("@");
  for(var i=1;i<objs.length;i+=2)
  {
   if(objs[i]!=""){
    var t=document.createElement("option");
    t.setAttribute("value",objs[i]);
    t.innerText=objs[i+1];
    document.getElementById("sele2").appendChild(t);
   }
  }
 }
}

```