日期:2014-05-20  浏览次数:20467 次

我这么写为什么不执行呢?哪错了呢?
HTML code

    <div class="compile_hull" id="divKey">
                 <img src="../images/loading.gif" vspace="40" />
                    </div>


JScript code

    var key = function (id) {
            $.ajax({
                type: "POST",
                url: '../rAjax/load_key.ashx',
                data: { id: id },
                success: function (msg) {
                    $("#divKey").html(msg);
                }

            });
        };



C# code

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

using System;
using System.Web;

public class load_key : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Request.ContentEncoding = System.Text.Encoding.UTF8;
        string pid = context.Request["id"];
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.Charset = "utf-8";
        context.Response.ContentType = "text/plain";
        context.Response.Write(test(pid));
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
    public string test(string id)
    {
        return "hahahahahah" + id;
    }

}



这么写为什么不执行呢?

------解决方案--------------------
JScript code

$(function(){
            $.ajax({
                type: "POST",
                url: '../rAjax/load_key.ashx',
                data: { id: "id" },
                success: function (msg) {
                    $("#divKey").html(msg);
                }

            });
        });

------解决方案--------------------
仓老师.... jquery 的ajax请求可以不写请求类型,但是一定要写返回类型
JScript code

$(function(){
            $.ajax({
                type: "POST",
                dataType: "json",
                url: '../rAjax/load_key.ashx',
                data: { id: "id" },
                success: function (msg) {
                    $("#divKey").html(msg);
                }

            });
        });