苹果 ios 微信浏览器界面 ajax 提交带 file 的 form 总是走error方法

1. 问题

问题出在微信端,而且是苹果机的微信端(苹果你咋这么矫情,安卓正常).;代码还是之前的代码,貌似是苹果升级系统后部分版本出现的 BUG,后来证明确实跟 ios 版本有关,网上也找过类似的解决措施;

2. 解决方法

2.1 添加 async: false(未验证)

function saveUser() {$.ajax({type:"POST",url:"SaveUser.action",data:$('#fm').serialize(),dataTyep:"JSON",async: false, //加上之后不在跳转进error
            success:function(data) {var config = confirm("注册成功,是否登陆");if(config){window.location.href="Login.action";}else{window.location.reload();}},error:function(){alert("系统异常");}});}

修改方法:在ajax里边加上了async: false, 原来是没有加它的,加上然后问题解决了

转:https://blog.csdn.net/bin929/article/details/80183443

2.2 ajaxFileUpload 提交(已验证)

最终采取这种方式处理的

ajaxFileUpload.js文件 ↓

jQuery.extend({createUploadIframe: function(id, uri){//create framevar frameId = 'jUploadFrame' + id;var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';if(window.ActiveXObject){if(typeof uri== 'boolean'){iframeHtml += ' src="' + 'javascript:false' + '"';}else if(typeof uri== 'string'){iframeHtml += ' src="' + uri + '"';}    }iframeHtml += ' />';jQuery(iframeHtml).appendTo(document.body);return jQuery('#' + frameId).get(0);            },createUploadForm: function(id, fileElementId, data){//create form    var formId = 'jUploadForm' + id;var fileId = 'jUploadFile' + id;var form = jQuery('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');    if(data){for(var i in data){jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);}            }/*old codevar oldElement = jQuery('#' + fileElementId);var newElement = jQuery(oldElement).clone();jQuery(oldElement).attr('id', fileId);jQuery(oldElement).before(newElement);jQuery(oldElement).appendTo(form);*//**** new code* support  multigroup、multi  fileupload* by keith* 2013-7-11* /**/if(typeof(fileElementId) == 'string'){fileElementId = [fileElementId];}for(var i in fileElementId){//按namevar oldElement = jQuery("input[name="+fileElementId[i]+"]");oldElement.each(function() {var newElement = jQuery($(this)).clone();jQuery(oldElement).attr('id', fileId);jQuery(oldElement).before(newElement);jQuery(oldElement).appendTo(form);});}//set attributesjQuery(form).css('position', 'absolute');jQuery(form).css('top', '-1200px');jQuery(form).css('left', '-1200px');jQuery(form).appendTo('body');        return form;},ajaxFileUpload: function(s) {// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout        s = jQuery.extend({}, jQuery.ajaxSettings, s);var id = new Date().getTime()        var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data));var io = jQuery.createUploadIframe(id, s.secureuri);var frameId = 'jUploadFrame' + id;var formId = 'jUploadForm' + id;        // Watch for a new set of requestsif ( s.global && ! jQuery.active++ ){jQuery.event.trigger( "ajaxStart" );}            var requestDone = false;// Create the request objectvar xml = {}   if ( s.global )jQuery.event.trigger("ajaxSend", [xml, s]);// Wait for a response to come backvar uploadCallback = function(isTimeout){            var io = document.getElementById(frameId);try {                if(io.contentWindow){xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;}else if(io.contentDocument){xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;}                        }catch(e){jQuery.handleError(s, xml, null, e);}if ( xml || isTimeout == "timeout") {                requestDone = true;var status;try {status = isTimeout != "timeout" ? "success" : "error";// Make sure that the request was successful or notmodifiedif ( status != "error" ){// process the data (runs the xml through httpData regardless of callback)var data = jQuery.uploadHttpData( xml, s.dataType );    // If a local callback was specified, fire it and pass it the dataif ( s.success )s.success( data, status );// Fire the global callbackif( s.global )jQuery.event.trigger( "ajaxSuccess", [xml, s] );} elsejQuery.handleError(s, xml, status);} catch(e) {status = "error";jQuery.handleError(s, xml, status, e);}// The request was completedif( s.global )jQuery.event.trigger( "ajaxComplete", [xml, s] );// Handle the global AJAX counterif ( s.global && ! --jQuery.active )jQuery.event.trigger( "ajaxStop" );// Process resultif ( s.complete )s.complete(xml, status);jQuery(io).unbind()setTimeout(function(){    try {jQuery(io).remove();jQuery(form).remove();    } catch(e) {jQuery.handleError(s, xml, null, e);}                                    }, 100)xml = null}}// Timeout checkerif ( s.timeout > 0 ) {setTimeout(function(){// Check to see if the request is still happeningif( !requestDone ) uploadCallback( "timeout" );}, s.timeout);}try {var form = jQuery('#' + formId);jQuery(form).attr('action', s.url);jQuery(form).attr('method', 'POST');jQuery(form).attr('target', frameId);if(form.encoding){jQuery(form).attr('encoding', 'multipart/form-data');                  }else{    jQuery(form).attr('enctype', 'multipart/form-data');            }            jQuery(form).submit();} catch(e) {            jQuery.handleError(s, xml, null, e);}jQuery('#' + frameId).load(uploadCallback    );return {abort: function () {}};    },uploadHttpData: function( r, type ) {var data = !type;data = type == "xml" || data ? r.responseXML : r.responseText;// If the type is "script", eval it in global contextif ( type == "script" )jQuery.globalEval( data );// Get the JavaScript object, if JSON is used.if ( type == "json" )eval( "data = " + data );// evaluate scripts within htmlif ( type == "html" )jQuery("<div>").html(data).evalScripts();return data;},//jquery在1.4以后不支持handleError
    handleError: function( s, xhr, status, e ) {// If a local callback was specified, fire itif ( s.error ) {s.error.call( s.context || s, xhr, status, e );}// Fire the global callbackif ( s.global ) {(s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );}}
})
View Code
    $.ajaxFileUpload({url : '/**/**.do',   //提交的路径secureuri : false, // 是否启用安全提交,默认为falsefileElementId: ["pic1","pic2"],    // file控件name属性!!!不是控件idtype: 'post',   //当要提交自定义参数时,这个参数要设置成postdataType : 'jsonp',/* data : {fileName : fileName   //传递参数,用于解析出文件名}, // 键:值,传递文件名 */success : function(data, status) {//alert("上传成功");},error : function(data, status) {alert(status);}});

 

<input type="file" id="pic1" name="pic1" accept="image/*">
<input type="file" id="pic2" name="pic2" accept="image/*">

 

本文地址:https://www.cnblogs.com/niceyoo/p/9404694.html

博客地址:https://www.cnblogs.com/niceyoo

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414731.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端学习(2748):uniapp创建项目和演示

1创建项目 2运行项目 3配置在微信小程序注意 配置路径 4注意开启端口号

HttpServletResponse.getWriter().print乱码,request.getHeader乱码,解决方法

1、添加响应类型即可 //这句话的意思&#xff0c;是让浏览器用utf8来解析返回的数据 response.setHeader("Content-type", "text/html;charsetUTF-8"); 添加前后&#xff1a; 如果是header参数乱码&#xff0c;解决方法如下&#xff1a; HTTP H…

设计图与html 对比

简易打开旧版火狐 网页版火狐添加组件 新版有时也会没有 谷歌是腾讯的转载于:https://www.cnblogs.com/byksj/p/8426291.html

jsr-303 参数校验-学习(转)

1、是什么&#xff1f; JSR303 是一套 JavaBean 参数校验的标准&#xff0c;它定义了很多常用的校验注解&#xff0c;比如&#xff1a;------------------------------------------------- NotNull(message"名字不能为空") private String userName; Max(value90,mes…

URLEncoder 、URLDecoder 对中文转码解码使用

URLEncoder 、URLDecoder 转码解码使用 传递参数&#xff0c;转码传递 String encodeStr null; try { encodeStr URLEncoder.encode("aabb22中国", "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.pr…

SQLServer DBA 三十问(加强版)

SQLServer DBA 三十问&#xff08;加强版&#xff09; 原文链接&#xff1a;http://www.cnblogs.com/fygh/p/3288701.html距离最初发布SQLServer DBA 三十问 已有一年多了&#xff0c;大家对其中的某些问题讨论比较激烈&#xff0c;要回答出来这些问题需要比较扎实的SQLServer …

jsr-303 参数校验—自定义校验注解

1、为什么要自定义&#xff1f; 通过上篇学习&#xff0c;了解到很多常用注解了&#xff0c;但是呢&#xff0c;总是有那么些需求....2、案例分析(手机号格式) 2.1、需要验证的实体 Bean public class LoginVo {NotNullIsMobile //自定义的注解private String mobile;NotNullLe…

关于Apache Tomcat解决localhost was unable to start within 45 seconds

关于重装myeclipse启动服务超时问题解决方法&#xff1a; 1.打开安装或解压了Tomcat的根目录 &#xff08;1&#xff09;temp&#xff08;项目临时缓存文件&#xff09; 里面的文件全部删除&#xff0c;不要犹豫&#xff0c;这是之前在对项目进行操作的时候&#xff0c;所产生…

[译]SQL SERVER 2016 – Temporal Tables

原文 Temporal Table是SQL Server2016的新特性。能存储你表里面任意时间点的数据信息。 换句话说&#xff0c;如果你针对一张表执行任何更新或者删除操作&#xff0c;老数据会被新数据覆盖&#xff0c;下次查询的时候是查的最新的数据&#xff0c;但如果使用了temporal table你…

拦截器、过滤器、@Aspect 区别

1、需求场景 之前也有在文章写道 “拦截器\过滤器" 的区别&#xff0c;文章链接&#xff0c;在实际开发过程中&#xff0c;我们可能会遇到拦截请求参数的需求&#xff0c;在这我举个场景。某一个接口的请求参数都是加密的&#xff0c;而请求参中还有一些跟业务无关的数据&…

工作231:给input动态赋值

这个应该是不可以的&#xff0c;必须重新使用用文件对话框选择。 这是处于安全的考虑&#xff0c;不能直接对input typefile的类型赋值&#xff0c;因为直接用JS就可以将你本地文件直接取到指定地点&#xff0c;就没有安全性可言。 因此必须对一个input typefile设置一个按钮来…

MyEclipse2015Stable2.0安装破解

java开发者不可避免需要使用到的开发工具——myeclipse2015。下载安装直接打开使用的话&#xff0c;使用期为30天&#xff0c;之后如果没有注册吗注册&#xff0c;就使用不了了。即使卸载重装还是提示试用期期限超限&#xff0c;无法打开使用。 于是就有了破解myeclipse2015方…

laravel5.5中间件

目录 1. 中间件知识1. artisan 命令2. 文件内容3. 前置中间件和后置中间件4. 使用中间件2. 控制器中间件1. 中间件知识 1. artisan 命令 php artisan make:middleware CheckAge 2. 文件内容 <?phpnamespace App\Http\Middleware;use Closure;class CheckAge {public functi…

JAVA spring 常用包作用详解(转)

转载地址&#xff1a;https://www.cnblogs.com/Tmc-Blog/p/6093162.html <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http:…

关于HttpUrlConnection网络请求之返回结果的中文乱码解决方法

解决方法&#xff1a; 原使用 StringBuffer改为使用StringBuilder即可 /** * 获取响应码 200成功 * 当响应成功&#xff0c;获取响应的流 */ int res conn.getResponseCode(); if(res…

日志汇总:logging、logger

目录 1、日志输出到文件 2、日志输出到屏幕 3、设置输出等级 4、设置多个日志输出对象 5、日志的配置 6、记录异常 7、设置日志输出样式1、日志输出到文件basicConfig()提供了非常便捷的方式让你配置logging模块并马上开始使用。什么都不配置直接使用默认值在控制台中打log&…

1、jeecg 笔记开篇

1. 前言 终究还是入了 jeecg 的 "坑"&#xff0c;国庆后公司采用该框架开发&#xff0c;故开篇记录。 虽说入"坑"&#xff0c;但不得不承认 jeecg 确实是一个非常强大的平台。 其实近几年凡是知名的开源框架都是采用代码生成器了&#xff0c;所以 jeecg 同…

工作233:定义有对话框的按钮

<!--定义一个有按钮的对话框 相当于dialog和按钮组合使用--> <template><!-- 有按钮的对话框 这个位置的代码会被包裹过去--><!--close-on-click-modal 是否可以通过点击 modal 关闭 Dialog append-to-body控制不能出现遮挡层--><el-dialog:title&q…