【问题标题】:How to redirect with variables after file upload文件上传后如何使用变量重定向
【发布时间】:2012-09-15 17:59:23
【问题描述】:

我有使用 jquery.filedrop.js 的拖放 jquery 脚本,并且在同一个资产文件夹中有一个 script.js。 Script.js 似乎是上传完成后显示结果的文件。上传完成后如何让它重定向到另一个页面? 下面是script.js

$(function(){
var myname = document.getElementById("myname").value;
var myid = document.getElementById("myid").value;
var mycat = document.getElementById("mycat").value;
var dropbox = $('#dropbox'),
    message = $('.message', dropbox);

dropbox.filedrop({
    // The name of the $_FILES entry:

    paramname:'pic',
    maxfiles: 100,
    maxfilesize: 2,
    //url: "post_file.php?id=33",
    url: "post_file.php?myid=" + myid + "&mycat=" + mycat + "&myname=" + myname ,

    uploadFinished:function(i,file,response){
        $.data(file).addClass('done');
        // response is the JSON object that post_file.php returns
    },

    error: function(err, file) {
        switch(err) {
            case 'BrowserNotSupported':
                showMessage('Your browser does not support HTML5 file uploads!');
                break;
            case 'TooManyFiles':
                alert('Too many files! Please select 5 at most! (configurable)');
                break;
            case 'FileTooLarge':
                alert(file.name+' is too large! Please upload files up to 2mb (configurable).');
                break;
            default:
                break;
        }
    },

    // Called before each upload is started
    //beforeEach: function(file){
        //if(!file.type.match(/^image\//)){
            //alert('Only images are allowed!');

            // Returning false will cause the
            // file to be rejected
            //return false;
        //}
    //},

    uploadStarted:function(i, file, len){
        createImage(file);
    },

    progressUpdated: function(i, file, progress) {
        $.data(file).find('.progress').width(progress);
    }

});

var template = '<div class="preview">'+
                    '<span class="imageHolder">'+
                        '<img />'+
                        '<span class="uploaded"></span>'+
                    '</span>'+
                    '<div class="progressHolder">'+
                        '<div class="progress"></div>'+
                    '</div>'+
                '</div>';

function createImage(file){

    var preview = $(template), 
        image = $('img', preview);

    var reader = new FileReader();

    image.width = 100;
    image.height = 100;

    reader.onload = function(e){

         //e.target.result holds the DataURL which
         //can be used as a source of the image:

        image.attr('src',e.target.result);
    };

    //reader.onload = window.parent.location.href="page2.htm";

    // Reading the file as a DataURL. When finished,
    // this will trigger the onload function above:
    reader.readAsDataURL(file);

    message.hide();
    preview.appendTo(dropbox);

    // Associating a preview container
    // with the file, using jQuery's $.data():

    $.data(file,preview);
}

function showMessage(msg){
    message.html("test")
}

问题是如何在上传完成后使用变量重定向。我试图在 var 模板区域中放置一些重定向代码...否

【问题讨论】:

    标签: jquery redirect drag-and-drop


    【解决方案1】:

    内部uploadFinished

    window.location.href = <some vars that create a string>;
    

    这就是你要找的吗?

    【讨论】:

    • 我试过uploadFinished: window.parent.location.href="page2.htm";它不起作用。
    • 知道了!语法错误。这行得通。 uploadFinished:function(i,file,response){ $.data(file).addClass('done'); window.location = 'mysite.com/users'; // response 是 post_file.php 返回的 JSON 对象 },
    猜你喜欢
    • 2019-07-18
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多