ravand
شنبه 12 فروردین 1396, 11:17 صبح
سلام
من میخوام با جاوا اسکریپت فایلی رو به سرور ارسال کنم اونم به تکنولوژی ایجکس. نمیخوام از فرم هم استفاده کنم. از جی کوئری و کتابخانه های دگه هم نمیخوام استفاده کنم.
اینجا یه مثالی گذاشته:
http://stackoverflow.com/questions/19617996/file-upload-without-form
var xmlHttpRequest = new XMLHttpRequest();
var file = ...file handle...
var fileName = ...file name...
var target = ...target...
var mimeType = ...mime type...
xmlHttpRequest.open('POST', target, true);
xmlHttpRequest.setRequestHeader('Content-Type', mimeType);
xmlHttpRequest.setRequestHeader('Content-Disposition', 'attachment; filename="' + fileName + '"');
xmlHttpRequest.send(file);
ولی نگفته باید به جای ...file handle... چی قرار بدم؟
من میخوام با جاوا اسکریپت فایلی رو به سرور ارسال کنم اونم به تکنولوژی ایجکس. نمیخوام از فرم هم استفاده کنم. از جی کوئری و کتابخانه های دگه هم نمیخوام استفاده کنم.
اینجا یه مثالی گذاشته:
http://stackoverflow.com/questions/19617996/file-upload-without-form
var xmlHttpRequest = new XMLHttpRequest();
var file = ...file handle...
var fileName = ...file name...
var target = ...target...
var mimeType = ...mime type...
xmlHttpRequest.open('POST', target, true);
xmlHttpRequest.setRequestHeader('Content-Type', mimeType);
xmlHttpRequest.setRequestHeader('Content-Disposition', 'attachment; filename="' + fileName + '"');
xmlHttpRequest.send(file);
ولی نگفته باید به جای ...file handle... چی قرار بدم؟