日期:2014-05-17  浏览次数:20513 次

使用jquery ajax 不进ashx页面,这什么问题,急急急...
前台
C# code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="zt_Default" %>

<!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="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            $("#confirm").click(function() {

                $.ajax({
                    url: 'Handler.ashx',
                    dataType: 'text',
                    data: 'id=1',
                    success: function(msg) {
                        alert(msg);
                    }
                });
            });

        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" value="确定" id="confirm" />
    </div>
    </form>
</body>
</html>



ashx页面
C# code


<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string x = context.Request.QueryString["id"].ToString();

        context.Response.Write('x');
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}


就是不进这个页面也不报错- -

------解决方案--------------------
$.ajax({
url: 'Handler.ashx',
dataType: 'text',
data: 'id=1',
success: function(msg) {
alert(msg);
}
});
需要加一个属性。
 $.ajax({
url: 'Handler.ashx',
type:"GET",
dataType: 'text',
data: 'id=1',
success: function(msg) {
alert(msg);
}
});

------解决方案--------------------
是不是缓存了?
url: 'Handler.ashx?tmp' + (new Date()).valueOf(),