Ajax Perfect Solution dropdown box to move

Source: Internet
Author: User
Tags add object bind return string tostring window
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);



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.