日期:2014-05-16 浏览次数:20738 次
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test11.aspx.cs" Inherits="Test11" %> <%--<%@ Register src="control/TestCity.ascx" tagname="TestCity" tagprefix="uc1" %>--%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <%-- <script src="js/ajax.js" type="text/javascript"></script>--%> <script type="text/javascript"> var xmlHttp = null; function loadXmlHttp() { if (window.XMLHttpRequest) { // IE7, Mozilla, Safari, Opera, etc. xmlHttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE 5.x and 6 } catch (e) { alert(e); } } } function sendRequest() { // alert(url); loadXmlHttp(); // alert(xmlHttp); if (xmlHttp) { // Open HTTP connection to url. xmlHttp.open("GET", "ChangeCity.ashx", true); // true = async // Define the callback function for async call xmlHttp.onreadystatechange = onCallback; // Specify form data in request body xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); // Send request without any additional parameters xmlHttp.send(null); } } function onCallback() { // Check for the completed status if (xmlHttp.readyState == 4) { // Check for successful server response if (xmlHttp.status == 200) { alert(xmlHttp.responseText); } else { // HTTP error alert('Error: ' + xmlHttp.status); } } } </script> </head> <body> <form id="form1" runat="server"> <div> <%-- <asp:Button runat="server" ID="bb1" Text="测试" OnClientClick=" sendRequest()" />--%> <input type="button" value="Cheshi" onclick="sendRequest()" /> <%-- <uc1:TestCity ID="TestCity1" runat="server" />--%> <input type="text" id="txt1" /> <select id="s1"></select> </div> </form> </body> </html>
<%@ WebHandler Language="C#" Class="ChangeCity" %> using System; using System.Web; using System.Web.Services; /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class ChangeCity : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "te