Ajax图片上传刷新手机上的页面
Ajax image upload refreshing the page on mobile
嗨,我有一个包含Ajax图像上传器的表单,它在桌面上运行良好,但当我尝试移动设备时,它会在图像被选中并丢失后导致页面刷新(更不用说我设置为在上传完成时运行的jquery的其他部分了)。
我发现了这个链接,Android浏览器在通过输入元素选择文件后刷新页面,尽管它提供了解释,但我可以看到并没有提供解决方案。那篇帖子是一年多前的事了,我在网上还没有找到其他解决方案。
必须有一个变通办法,因为我可以看到它在其他网站上运行,例如。http://www.putmeinthestory.com/
代码:
<form action="index.php?route=product/product/image_upload" onSubmit="return false" method="post" enctype="multipart/form-data" class="MyUploadForm">
<input name="FileInput" id="FileInput" type="file" /><br />
<input type="submit" id="submit-btn" value="Upload File »" />
</form>
<div id="output"></div>
Javascript:我不确定发布下面调用的所有函数是否与这个问题有关。
var options = {
target: '#output', // target element(s) to be updated with server response
beforeSubmit: beforeSubmit, // pre-submit callback
success: afterSuccess, // post-submit callback
uploadProgress: OnProgress, //upload progress callback
resetForm: true // reset the form after successful submit
};
jQuery('.MyUploadForm').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
我想我可能已经通过稍微更改代码来解决了这个问题。。。我从form
标记中删除了该操作,并将url包含在ajax中。
也许问题不在于安卓系统。(尽管我仍然很困惑,如果是这样的话,为什么这个问题一直出现在SO上。)
我还不想给它一个正确的答案,直到我确认它在各种设备上都能工作。
<form action="" onSubmit="return false" method="post" enctype="multipart/form-data" class="MyUploadForm">
var options = {
url: 'index.php?route=product/product/image_upload',
target: '#output', // target element(s) to be updated with server response
beforeSubmit: beforeSubmit, // pre-submit callback
success: afterSuccess, // post-submit callback
uploadProgress: OnProgress, //upload progress callback
resetForm: true // reset the form after successful submit
};
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在php文件中获取$.post-ajax传递的值
- Replacing $ .ajax?
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- Ajax发布表单序列化,发布引号'
- 通过Ajax将JavaScript函数传递给PHP文件
- ajax请求的顺序总是不同的
- 可以't使用Polymer's的核心ajax
- Ajax Live搜索发布到Laravel视图
- Ajax聊天消息重复而不仅仅是更新
- 从控制器返回后Ajax启动事件激发
- PHP AJAX图片上传示例不上传
- 从ajax请求中获取javascript对象
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 如何在Javascript中解析AJAX数组的特定部分
- Ajax文件加载和<输入>文件加载
- Javascript/jQuery中的并行Ajax调用
- Ajax-如何获取数据
- JS验证ajax返回的html中的表单数据