日期:2014-05-20 浏览次数:20561 次
<div class="compile_hull" id="divKey">
<img src="../images/loading.gif" vspace="40" />
</div>
var key = function (id) {
$.ajax({
type: "POST",
url: '../rAjax/load_key.ashx',
data: { id: id },
success: function (msg) {
$("#divKey").html(msg);
}
});
};
<%@ 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;
}
}
$(function(){
$.ajax({
type: "POST",
url: '../rAjax/load_key.ashx',
data: { id: "id" },
success: function (msg) {
$("#divKey").html(msg);
}
});
});
------解决方案--------------------
仓老师.... jquery 的ajax请求可以不写请求类型,但是一定要写返回类型
$(function(){
$.ajax({
type: "POST",
dataType: "json",
url: '../rAjax/load_key.ashx',
data: { id: "id" },
success: function (msg) {
$("#divKey").html(msg);
}
});
});