在你的ashx中,你需要從閱讀帖子數據中獲取數據。
StringBuilder HttpInputStream;
public void ProcessRequest(HttpContext context)
{
HttpInputStream = new StringBuilder();
GetInputStream(context);
// the data will be in the HttpInputStream now
// What you might want to do it to use convert it to a .Net class ie,
// This is using Newtonsoft JSON
// JsonConvert.DeserializeObject<JsonMessageGet>(HttpInputStream.ToString());
}
private void GetInputStream(HttpContext context)
{
using (Stream st = context.Request.InputStream)
{
byte[] buf = new byte[context.Request.InputStream.Length];
int iRead = st.Read(buf, 0, buf.Length);
HttpInputStream.Append(Encoding.UTF8.GetString(buf));
}
}
在您的回覆調用者 - 您的ashx需要以JSON響應,以便調用者JavaScript可以使用它。
我建議使用Newstonsoft JSON如...
public void ProcessRequest(HttpContext context)
{
// read from stream and process (above code)
// output
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(JsonConvert.SerializeObject(objToSerialize, new IsoDateTimeConverter()));
}
,或者使它真的很容易,變化 - 基本上需要在JSON響應回JavaScript的處理程序來處理它
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
context.Response.Write("{data:\"Reply message\"}");
}
汗是使用C#不是PHP – 2010-06-08 08:32:11
嗨@Jason不是PHP。 JQuery的。這個問題不清楚哪個處理程序沒有被調用。 MyHandler.ashx或回調處理程序。猜測它是ashx處理程序。我會修改這個問題,使之更加清晰。 – 2010-06-08 08:39:01
它不能正常工作 – KhanS 2010-06-08 09:27:38