test.aspxy页面是别人的页面,就是处理后提交给别人处理。 处理流程是这样的: web Service 处理后提交给 ashx页面处理,ashx页面处理后提交给其他的aspx页面处理。从ashx页面到test.axps页面的代码处理是没有问题的。 现在的问题是:从 web Service 提交给ashx 页面处理了,ashx页面提交test.axps,test.axps就接收不倒数据; 如果是从aspx页面提交给ashx 页面处理,ashx页面提交test.axps,test.axps就能接收数据。 不知道我说清楚类没有
//接受信息处理,处理后将信息提交到其他的aspx页面
StringBuilder to = new StringBuilder();
to.Append("<form id=\"F_orm\"");
to.Append(" action=\"test.aspx\"");
to.Append(" methoh=\"post\">");
to.Append(" <input type=\"hidden\" id=\"test1\" name=\"test1\" value=\"testvalue\">");
to.Append("</form>");
context.Response.ContentType = "text/html;charset=UTF-8" ;
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
context.Response.Write(to.ToString()); context.Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
context.Response.Write(" var tform = document.getElementById('F_orm');");
context.Response.Write(" tform.submit();");
context.Response.Write("</script>");
context.Response.Flush();
context.Response.Close(); test.aspx 页面接受不到信息
var test = function () {
var data = "Time=" + new Date();
$.ajax({
type: "get", url: "/Handler.ashx", data: data,
success: function (result) {
//这里你再转到test.aspx
window.location.href = "test.aspx?data=" + result;
//或者把result写入COOKIES,到test.aspx页面中去获取此COOKIE
}
});
}
</script>
<form method="post" action="Ajax/Help/Ajax_Help.ashx?method=AnswerAdd" class="pageForm"
onsubmit="return validateCallback(this, dialogAjaxDone)">
<div class="pageFormContent" layouth="50">
<p>
<label>Question:</label>
<label><%=QuestionModel.Name %></label>
<input type="hidden" name="QuestionID" value='<%=QuestionModel.ID %>' />
</p>
<p>
<label>AnswerID:</label>
<input type="text" readonly="readonly" name="Answer_id" size="30" class="required" value='<%=MaxAnswerID %>' />
</p>
<p>
<label>AnswerName:</label>
<input type="text" name="name" size="30" class="required" alt="Please input Name"/> </p>
<p>
<label>IsTrue:</label>
<input type="checkbox" name="able" checked="checked" />
</p>
</div>
<div class="formBar">
<ul>
<li>
<div class="buttonActive">
<div class="buttonContent">
<button type="submit">
Commit</button></div>
</div>
</li>
<li>
<div class="button">
<div class="buttonContent">
<button type="button" class="close">
Cancel</button></div>
</div>
</li>
</ul>
</div>
</form>
public void AnswerAdd(HttpContext context)
{
try
{
OnlineQuiz.Model.M_Answers QAnswersModel = new OnlineQuiz.Model.M_Answers(); QAnswersModel.Question_ID = Convert.ToInt32(context.Request.Form["QuestionID"]);
QAnswersModel.Name = context.Request.Form["name"].ToString();
QAnswersModel.ID = Convert.ToInt32(context.Request.Form["Answer_id"]);
QAnswersModel.Istrue = 0;
if (context.Request.Form["able"] == "0" || context.Request.Form["able"] == "on")
{
QAnswersModel.Istrue = 1;
}
SqlParameter[] iData = {new SqlParameter("@Answer_ID",SqlDbType.Int,4),
new SqlParameter("@Answer_Name",SqlDbType.NVarChar,50),
new SqlParameter("@Question_ID",SqlDbType.Int,4),
new SqlParameter("@Answer_IsTrue",SqlDbType.Int,4)}; iData[0].Value = QAnswersModel.ID;
iData[1].Value = QAnswersModel.Name;
iData[2].Value = QAnswersModel.Question_ID;
iData[3].Value = QAnswersModel.Istrue;
SqlHelper.ExecuteNonQuery("Proc_AnswerAdd", iData, CommandType.StoredProcedure);
context.Response.Write("{\"statusCode\":\"200\", \"message\":\"Sucess!!!\", \"navTabId\":\"sanswer\", \"forwardUrl\":\"Admin/AnswerInfo.aspx?id=" + QAnswersModel.Question_ID + "\", \"callbackType\":\"forward\"}");
}
catch
{
context.Response.Write("{\"statusCode\":\"300\", \"message\":\"" + Help.GetError + "\", \"navTabId\":\"sanswer\", \"forwardUrl\":\"Admin/AnswerInfo.aspx\", \"callbackType\":\"forward\"}");
}
}
处理流程是这样的:
web Service 处理后提交给 ashx页面处理,ashx页面处理后提交给其他的aspx页面处理。从ashx页面到test.axps页面的代码处理是没有问题的。
现在的问题是:从 web Service 提交给ashx 页面处理了,ashx页面提交test.axps,test.axps就接收不倒数据;
如果是从aspx页面提交给ashx 页面处理,ashx页面提交test.axps,test.axps就能接收数据。 不知道我说清楚类没有
现在的问题是test.aspx 是外部系统的,而且只接受post表单提交的数据。
我已经在Web Service 使用
System.Net.WebClient WebClientObj = new System.Net.WebClient();
WebClientObj.UploadValues(url,"POST", pars);
(使用HttpWebRequest也可以)
向 ashx文件中提交请求了。而且ashx也接受到数据了。只是这个时候ashx页面向其他的aspx页面提交数据,aspx页面就接收不倒了
在web Service 中 用HttpWebRequest 提交到ashx文件中,处理后ashx文件利用post提交到其他的aspx页面