如题,
我用一个aspx 页面写js请求一个一般处理程序
然而,给我返回的却是是aspx整个页面的代码,
我在一般处理程序里面设置断点, 竟然没有跳过去
这是不是能说明,他请求没成功。
但是,ajax返回来的那两个状态却是成功的
readystate==4
staus==200
这是为何呢,
求高手解答!!
一下是代码
- C# code
<%@ 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>
- C# code
<%@ 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 = "text/plain"; //context.Response.Write("javascript:alert(1111)"); context.Response.Write("0000000000000"); // context.Response.End(); } //public void GetDate(HttpContext context) //{ // string ss = context.Request["id"].ToString(); // // string[] aa = { }; // context.Response.Write(ss); //} public bool IsReusable { get { return false; } } }