سؤال

وأنا خلق تطبيق ويب باستخدام الكؤوس المقدسة والذي يستخدم الكثير من ajax.I يريدون تنفيذ تحميل الملفات باستخدام ajax.I لا أعرف كيفية استخدام اياكس لرمز ملف upload.My عينة GSP هو:

<!-- code for file upload form-->
<div id="updateArea">

</div>

وحاولت مع و. بعد تحميل أريد لتحديث "updateArea" مع نتيجة result.In وأنا على التخطيط لإظهار تفاصيل الملف الذي تم تحميله.

هل كانت مفيدة؟

المحلول

تحميل ملف عبر اياكس ليس من الممكن حقا. لا يزال بإمكانك تحميل ملف في الخلفية باستخدام الإطار من المخفي وإما تقييم repsonse (وهو ثم داخل إطار iframe) أو إطلاق دعوة اياكس أخرى بعد اكتمال التحميل.

<g:form name="upload-form" action="upload" method="post" enctype="multipart/form-data" target="hidden-upload-frame">
    File: <input type="file" name="myFile" />
    <button type="submit">Upload</button>
</g:form>

<iframe id="hidden-upload-frame" name="hidden-upload-frame" style="display: none" onload="onUploadComplete">
</iframe>

<script type="text/javascript">
    function onUploadComplete(e) {
        // Handle upload complete
        alert("upload complete");
        // Evaluate iframe content or fire another ajax call to get the details for the previously uploaded file
    }
</script>

وثمة خيار آخر هو استخدام فلاش على أساس آلية تحميل (على سبيل المثال. swfupload ) بدلا من IFRAME.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top