Ajax| Solution | Pull down
The next step, of course, is to define the XMLHttpRequest object.
var xmlhttp;
function Createxmlhttp ()
{
Non IE browser Create XMLHttpRequest object
if (window. XMLHttpRequest)
{
Xmlhttp=new XMLHttpRequest ();
}
IE Browser Create XMLHttpRequest object
if (window. ActiveXObject)
{
Try
{
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
try{
Xmlhttp=new ActiveXObject ("MSXML2"). XMLHTTP ");
}
catch (ex) {}
}
}
}
This in my many blog articles have elaborated, do not say more.
The next step, of course, is to use the object to send the condition, get the data, and bind the obtained data to the agent's Drop-down box.
The onchange event inside the area dropdown box triggers the function ajaxsend ();
function Ajaxsend ()
{
Creating XMLHttpRequest Objects
Createxmlhttp ();
if (!xmlhttp)
{
Alert ("Create XMLHttpRequest exception!") ");
return false;
}
Gets the value value of the Region Drop-down box, which is sent as a condition
var Ss=document.getelementbyid ("A2"). Value.substring (0,4);
}
Url,userajax to send I'm dedicated to fetching data.
Url= "Userajax.aspx?area=" +SS;
Xmlhttp.open ("POST", Url,false);
Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4)
{
if (xmlhttp.status==200)
{
Empty the original dropdown box
document.getElementById ("Agent"). options.length=0;
STR is returned as a string, in the form of "0001/Agent 1,0002/Agent 2,0003/Agent 3"
var Str=xmlhttp.responsetext;
Splits the string into an array form
var strs=str.split (",");
document.getElementById ("Agent"). Options.add (New Option ("----------", "000000"));
for (Var i=0;i{
Get Value (number)
var a=strs[i].substring (0,strs[i].lastindexof ("/"));
Get bound content
var b=strs[i].substring (Strs[i].lastindexof ("/") +1,strs.length);
Bind to drop down box
document.getElementById ("Agent"). Options.add (New Option (B,a));
}
}
}
}
Xmlhttp.send ();
}
Also, incidentally, the process by which Userajax receives the data return string after receiving the region number.
String area = request.querystring[' Area ']. ToString ();
DataTable data = "Generate a DataTable, involving the company's core code, omitting"
string aa = "";
for (int i = 0; i < data. Rows.Count; i++)
{
if (aa = "")
{
AA = data. rows[i]["id"]. ToString () + "/" +data. rows[i]["Name"]. ToString ();
}
Else
{
AA = AA + "," + data. rows[i]["id"]. ToString () + "/" + data. rows[i]["Name"]. ToString ();
}
}
Response.Write (AA);