In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to use frameless Ajax in ASP.NET. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
We need two pages a.aspx, b.aspxjina page code as follows (using the most common example of two drop-down lists linked together):
< body > < form id= "Form1" method= "post" runat= "server" > < select id= "AList" onchange=SetBList () > < option value= "0" > A < / option > < option value= "1" > B < / option > < option value= "3" > C < / option > < / select > < select id= "BList" > < / select > < / form > < / body >
When the onchange event is triggered on page a, we enter the SetBList () method written on page a, where the complete js is listed:
< script language= "javascript" > var xmlHttp;function SetBList () {var avalue = document.getElementById ("AList"). Value; var url = "b.aspxroomAvalue =" + avalue; createXMLHttpRequest (); / / create xmlHttp object xmlHttp.onreadystatechange = handleStateChange; / / when the xmlHttp status code changes, call the handleStateChage method xmlHttp.open ("GET", url, true); / / the GET method sends the request xmlHttp.send (null) } function BListInitial () {/ / clear BList's option clearBList (); var blist = document.getElementById ("BList"); / / get BList object var rs = xmlHttp.responseXML.getElementsByTagName ("City") / / read the data of the < City > tag from the returned xml document / / the place where the loop takes the value, stuck me for a while, created the xmlHttp.responseXML into a xml document, and then found a way to read the document, but the problem is that different browsers create xml documents in different ways, for (var itemosi < rs.length;i++) {var option = document.createElement ("OPTION") Option.text = rs[ I] .getElementsByTagName ("CityName"); option.value = rs[ I] .getElementsByTagName ("CityCode"); blist.options.add (option);} function clearBList () {var ven = document.getElementById ("VendorList"); while (ven.options.length > 0) ven.removeChild (ven.childNodes [0]) } function handleStateChange () {if (xmlHttp.readyState = = 4) {if (xmlHttp.status = = 200) {BListInitial ();} function createXMLHttpRequest () {/ / IE if (window.ActiveXObject) {xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");} / Mozilla else if (window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest ();}} < / script >
The b.aspx page removes all the html sections, leaving only one line:
<% @ Page language= "c #" Codebehind= "b.aspx.cs" AutoEventWireup= "false" Inherites= "Test.Ajax"% >
The reason is that our a page requires the returned xml document, so we delete the Html tag part. Then, in the Page_Load method of the b page, manipulate the database, and then write the data in xml format, for example:
/ / Database operation, get DataTable dtstring xml = "< Data >"; foreach (DataRow row in dt.Rows) {xml + = "< City >"; xml + = "< CityName >" + row ["CityName"] + "< / CityName >"; xml + = "< CityCode >" + row ["CityCode"] + "< / CityCode >"; xml + = "< / City >";} xml + = "< / Data >"; / / clear the page format and write xmlResponse.ClearContent () Response.Cache.SetNoStore (); Response.ContentType = "text/xml"; Response.ContentEncoding = System.Text.Encoding.UTF8;Response.Write (xml)
You can test the b page before running it as a whole, and if you get a result similar to the following, it means that the data part is fine.
-< Data >-< Vendor > < VendorId > 7 < / VendorId > < VendorName > thousands < / VendorName > < / Vendor > < / Data > the above is shared by Xiaobian on how to use frameless Ajax in ASP.NET. If you happen to have similar doubts, please refer to the above analysis for understanding. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.