我现在需要上传一个文件和一个值分别用到如下Jquery函数:
jQ.ajax
({
type: "post",
url: 'Handler.ashx',
data: {Orderid:id},
success: function (data) {
alert(data.toLocaleString);
},
error: function (error) { alert(error.toString); },
}); jQ("#form1").ajaxSubmit({
success: function (str) {
if (str != null && str != "undefined") {
if (str[0] == "1") { alert("上传成功"); }
else if (str == "2") { alert("只能上传Excel格式的图片"); }
else if (str == "3") { alert("图片不能大于1M"); }
else if (str == "4") { alert("请选择要上传的文件"); }
else { alert('操作失败!'); }
}
else alert('操作失败!');
},
error: function (error) { alert(error.toString); },
url: 'Handler.ashx',
type: "post",
dataType: "text"
});但是后台代码该怎么写呢,只有一个HttpContext啊,我要怎么响应两个ajax的请求啊我这样写:
string OrderId = context.Request.Form["Orderid"];
context.Response.Write("1");
HttpPostedFile _upfile = context.Request.Files["File1"];
context.Response.Write("msg");
context.Response.End();
不行啊!!!!第一个响应得要id后 第二个就拿不到文件了
jQ.ajax
({
type: "post",
url: 'Handler.ashx',
data: {Orderid:id},
success: function (data) {
alert(data.toLocaleString);
},
error: function (error) { alert(error.toString); },
}); jQ("#form1").ajaxSubmit({
success: function (str) {
if (str != null && str != "undefined") {
if (str[0] == "1") { alert("上传成功"); }
else if (str == "2") { alert("只能上传Excel格式的图片"); }
else if (str == "3") { alert("图片不能大于1M"); }
else if (str == "4") { alert("请选择要上传的文件"); }
else { alert('操作失败!'); }
}
else alert('操作失败!');
},
error: function (error) { alert(error.toString); },
url: 'Handler.ashx',
type: "post",
dataType: "text"
});但是后台代码该怎么写呢,只有一个HttpContext啊,我要怎么响应两个ajax的请求啊我这样写:
string OrderId = context.Request.Form["Orderid"];
context.Response.Write("1");
HttpPostedFile _upfile = context.Request.Files["File1"];
context.Response.Write("msg");
context.Response.End();
不行啊!!!!第一个响应得要id后 第二个就拿不到文件了
解决方案 »
- 如何通过XPS虚拟打印机打印任一格式的文件,而不弹出对话框?
- C#调用摄像头抓图时出现"尝试读取或写入受保护的内存..."
- as string和 tostring()有什么区别吗?
- 请教cookie更新滞后问题
- C#中的TreeView 控件树状控件怎么用?
- 请大侠指点!datagrid更新的问题
- 怎么根据一个xml文档的结构建一个sql表,然后用xml文档数据填充这张表
- UltraWebGrid中checkBox问题,checBox总为false!
- http://www.szlen.com的程序是怎么做的,大家交流
- 各位大哥,帮帮我!!!
- 测试:单文件夹文件数量 200W 对 WEB 访问的性能影响
- c# 数据库 sqlcommandbuilder
你这样客户端分两次提交,那么服务器端又要一起处理,很显然一次得不到id,一次得不到文件。
把你的OrderID 作为input放进 #form1
<form id="form1" method="POST" action="youraction">
<input type="file" id="File1"/>
</form>
改成
<form id="form1" method="POST" action="youraction">
<input type="file" id="File1"/>
<input type="hidden" id="orderInput"/>
</form>然后在你 jQ("#form1").ajaxSubmit 之前
$("#orderInput").val(orderId);ashx里面接受的POST会有数据的。