這是關於在非text/string數據上使用Ajax的常見問題。提交前從表單圖像數據中使用Ajax
是否有可能在窗體中使用選定圖像執行JQuery Ajax POST請求?這是提交之前預覽處理的圖像,從表單輸入採取。該圖像被髮布到做一些圖像處理的服務器上,並將返回img html。
例如:
var img = $('#form').find('input:first, select:first').first(); // the image/file input
$.ajax({
type: "POST",
url: "photoprocess.php",
data: "{prephoto: '" + img+ "'}", // ??
contentType: "application/jpeg; charset=utf-8",
dataType: "text",
success: function (response) {
var imgHtml = response.d;
$('#preview').empty();
$('#preview').append(""+imgHtml);
},
......
如果需要的插件,我應該去爲哪一個?或更好的措辭:有沒有一個插件,你有這個解決方案的良好經驗?
乾杯。
看看http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery它有一些解決方案,用jQuery上傳文件 – mguymon 2012-03-17 01:11:26
看起來像我必須使用插件。 – gorn 2012-03-17 01:21:07