1

我有一个脚本,它需要上传的 csv,并通过 ajax 将数据传递给 php 脚本以进行字段验证。这很完美。php 以结果响应,并将其显示在页面上。假设 php 脚本返回并说“您需要更改字段 X”,然后用户将更新他的 csv 并再次单击添加文件按钮以尝试重试。这第二次尝试失败。添加文件按钮会打开浏览窗口,但页面从不显示新的 csv 数据。任何想法?

 <script>
 $('#thefile').change(function(){
   $('#path').val($(this).val());
 });

 $(document).ready(function() {
     $('#thefile').change(function(e) {
    if (e.target.files != undefined) {
        var reader = new FileReader();

 var theInfo = "";
 var file = document.getElementById('thefile').files[0];
        reader.onload = function(e) {
 var lenlen = e.target.result.split('\n').length;
 for (i =0;i<lenlen;i++)
 {
    theInfo += "data["+i+"]="+e.target.result.split('\n')[i]+"&";
 }
 $.ajax({
    url: "users/checkCSV.php",
    type: "POST",
    data: theInfo,
    processData: false,
    success: function(result)
 {
 $('#uploadResults').html(result);
 }
});

        };

        reader.readAsText(e.target.files.item(0));
    }

    return false;
});
 });

 </script>


 <form>
 <div id='fileButton'>
 <label class="add-photo-btn">Add file....
     <span>
   <input type="file" id="thefile" name="thefile" />
     </span>
   </label>
 </form>
 </div>
4

0 回答 0