jquery implements asynchronous upload files compatible with IE8

  • 2020-06-15 07:39:14
  • OfStack

Case study:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Untitled document </title>
<script type="text/javascript" src="jquery.min.js"></script>
<script src="upload02.js"></script>
<script type="text/javascript">
 
  function look() {
    //alert($("form input[type=file]").val())
    alert($("input[name=test]").upload("getFileVal"))
  }
  function clean() {
    $("input[name=test]").upload("clean")
  }
  function ajaxSubmit() {
    $("input[name=test]").upload({
      url: 'index.aspx',
      //  Other form data 
      params: { name: 'pxblog' },
      //  After uploading ,  return json, text
      dataType: 'json',
      onSend: function (obj, str) { return true; },
      //  Call back after upload 
      onComplate: function (data) {
        alert(data.file);
      }
    });
    $("input[name=test]").upload("ajaxSubmit")
  }
  function look1() {
    //alert($("form input[type=file]").val())
    alert($("input[name=test1]").upload("getFileVal"))
  }
  function clean1() {
    $("input[name=test1]").upload("clean")
  }
  function ajaxSubmit1() {
    $("input[name=test1]").upload({
      url: 'index.aspx',
      //  Other form data 
      params: { name: 'pxblog' },
      //  After uploading ,  return json, text
      dataType: 'json',
      onSend: function (obj, str) { return true; },
      //  Call back after upload 
      onComplate: function (data) {
        alert(data.file);
      }
    });
    $("input[name=test1]").upload("ajaxSubmit")
  }
</script>
</head>
 
<body>
  <p>
<input type="button" value="look" onclick="look()" />
<input type="button" value="clean" onclick="clean()" />
<input type="button" value="ajaxSubmit" onclick="ajaxSubmit()" />
<input type="file" name="test" />
  </p>
  <p>
<input type="button" value="look1" onclick="look1()" />
<input type="button" value="clean1" onclick="clean1()" />
<input type="button" value="ajaxSubmit1" onclick="ajaxSubmit1()" />
<input type="file" name="test1" />
  </p>
</body>
</html>

Source: http: / / code. taobao. org/p/upload2 / src/jquery upload2. js

The environment I tested was IE10, which simulated IE8 in the developer tool of IE10, and the test passed. (I have set the security permissions on the browser, so it shouldn't matter)

Fixed 1 minor bug written by this person, added several methods, mainly passed IE8 test (IE8 was not supported before).

This is the end of this article, I hope you enjoy it.


Related articles: