嗨朋友我有一個窗體,其中有一些文本框,下拉式以及圖像。我正在使用js來保存表格細節。我正在使用uploadify插件將我的圖像上傳到本地文件夾。我實現了所有這些功能,但是直到現在我還是使用了一個aspx代碼。爲了上傳目的,我們必須選擇ashx。所以它會像兩個服務器端發佈一樣發生!使用uploadify與ashx處理程序
所以我想將我的數據保存在ashx頁面而不是aspx。
但是我很困惑在哪裏開始我的upload.please有人幫助我這個!
我正在保存我的值在像下面的保存按鈕事件!
self.AddEvent = function (args) {
// Here--> $('#file_upload').uploadify('upload');
ajax.Post("../Scripts/uploadify/UploadHandler.ashx", JSON.stringify({ objEnt: args }), false).success(function (data) {
if (data.d[0] > 0) {
// or Here--> $('#file_upload').uploadify('upload');
alert('success');
}
和我的文件上傳設定S1是:
$('#file_upload').uploadify({
'swf': '../Scripts/uploadify/uploadify.swf',
'uploader': '../Scripts/uploadify/UploadHandler.ashx',
'method': 'post',
'formData': { 'someKey': Filename },
'buttonText': 'Browse',
'auto': false,
'folder': 'upload',
'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png',
'onSelect': function (file) {
var ext = file.name.split('.').pop();
$("#filename").val(Filename + '.' + ext);
},
'onUploadSuccess': function (file, data, response) {
if (response == true) {
$("#eventGrid").jqxGrid('updatebounddata');
}
}
});
這是不可能調用self.AddEvent在我的情況 'onUploadsuccess' ... !!! 請給我建議一些最好的方式來存儲我的數據和圖像在ashx處理程序中的同一時間。
ASHX:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
var data = context.Request;
var sr = new StreamReader(data.InputStream);
var stream = sr.ReadToEnd();
var javaScriptSerializer = new JavaScriptSerializer();
var asd = javaScriptSerializer.Deserialize<RootObject>(stream);
string Newname = context.Request.Form["someKey"];
BAL Bl = new BAL();
string[] args = new string[2];
//AddEvent method will add my data into database add return response "Success"//
args = AddEvent(asd.objEnt);
HttpPostedFile PostedFile = context.Request.Files["Filedata"];
string ext = Path.GetExtension(PostedFile.FileName);
string savepath = "";
string temppath = "";
temppath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
savepath = context.Server.MapPath(temppath);
string fileName = Newname + ext;
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
PostedFile.SaveAs(savepath + @"\" + fileName);
context.Response.Write(temppath + "/" + fileName);
// context.Response.Write(args);
context.Response.StatusCode = 200;
}
}
你可以使用它像這樣,第一次加載所有圖像後,如果成功的情況發生,在uplodify成功裏面,使anaother AJAX調用,它具有保存數據 – sakir
不過說我一件事我怎麼能得到ashx處理程序的響應返回的值?我知道context.response.write(args)會在控制檯中寫入。但是,我怎麼能得到Ajax成功返回的值? – user3640046
在ashx中使用會話 – sakir