Jquery 文件上传后如何使用变量重定向

Jquery 文件上传后如何使用变量重定向,jquery,redirect,drag-and-drop,Jquery,Redirect,Drag And Drop,我有一个使用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 = d

我有一个使用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 myname=document.getElementById(“myname”).value;
var myid=document.getElementById(“myid”).value;
var mycat=document.getElementById(“mycat”).value;
var dropbox=$(“#dropbox”),
消息=$('.message',dropbox);
dropbox.filedrop({
//$\u文件项的名称:
参数名称:'pic',
最大文件数:100,
最大文件大小:2,
//url:“post_file.php?id=33”,
url:“post_file.php?myid=“+myid+”&mycat=“+mycat+”&myname=“+myname,
上传完成:函数(i、文件、响应){
$.data(文件).addClass('done');
//response是post_file.php返回的JSON对象
},
错误:函数(错误,文件){
开关(错误){
案例“BrowserNotSupported”:
showMessage('您的浏览器不支持HTML5文件上传!');
打破
“TooManyFiles”案例:
警报('文件太多!请最多选择5个!(可配置)';
打破
案例“FileTooLarge”:
警报(file.name+'太大!请上载最大2mb的文件(可配置)。';
打破
违约:
打破
}
},
//在每次上载开始之前调用
//beforeach:函数(文件){
//如果(!file.type.match(/^image\//)){
//警报('只允许使用图像!');
//返回false将导致
//要拒绝的文件
//返回false;
//}
//},
uploadStarted:函数(i、文件、len){
创建图像(文件);
},
ProgressUpdate:功能(i、文件、进度){
$.data(文件).find('.progress').width(进度);
}
});
变量模板=“”+
''+
'

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

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

这就是你要找的吗?

我试过uploadFinished:window.parent.location.href=“page2.htm”;但它不起作用。明白了!语法错误。这很有效。uploadFinished:function(I,file,response){$.data(file.addClass('done');window.location='';//response是post\u file.php返回的JSON对象},