我正在尝试使用 JSON、AJAX 和 JQUERY 从 httphandler 文件向客户端发送两条连续消息。但是,仅显示第二条消息。可能是什么原因?你如何显示这两条消息?
.ASHX
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;
public class Gen_BLL : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string ename = JsonConvert.SerializeObject("Message1..");
context.Response.Clear();
context.Response.ContentType = "application/json; charset=utf-8";
context.Response.Write(ename);
ename = JsonConvert.SerializeObject("Message2..");
context.Response.Clear();
context.Response.ContentType = "application/json; charset=utf-8";
context.Response.Write(ename);
}
public bool IsReusable {
get {return false;}
}
}
.JS 文件:
function funGenAst(usro){
$.ajax({
type: "GET",
url: "Gen_BLL.ashx",
contentType: "application/json; charset=utf-8",
data: { "uso": usro },
dataType: "json",
success: OnComplete,
error: OnFail
});
return false;
}
function OnComplete(result) {
alert(result);
}
function OnFail(result){
alert("fail...');
}
只显示一个警报,即“Message2..”。“Message1..”警报根本没有弹出。您如何一个接一个地提醒这两条消息?
谢谢 bsc