日期:2014-05-17 浏览次数:20400 次
<head> <script src="../JS/jquery-1.7.2.min.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> $.ajax({ type: "POST", url: "Demo.ashx", dataType: "text", async: true, cache: false, data: { name: 'test' }, success: function(data) { }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert('当你狂刷新页面的时候就弹出来了'); } }); </script> </body> </html>
<%@ WebHandler Language="C#" Class="Demo" %> using System; using System.Web; public class Demo : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("1"); } public bool IsReusable { get { return false; } } }
data: { "val1": v1, "val2": v2 }, //注意!!!ASHX和WebService传data格式不同!!这是WS的 data: "{val1:'" + v1 + "',val2:'" + v2 + "'}",
------解决方案--------------------
我当时碰到的问题跟你一样 后来就是data传值写法不一样 你可以试试先
POST 修改成 GET
------解决方案--------------------
context.Response.ContentType = "text/plain"; string ss = context.Request.Params["name"];//接受一下提交值 context.Response.Write("1");