我使用插件上传工作正常的图片,代码为:
$('input[name=photo]').change(function(e) {
var file = e.target.files[0];
$.canvasResize(file, {
width: 600,
height: 500,
crop: false,
quality: 90,
callback: function(data, width, height) {
if(width > 100)
{
}
else
{
alert("this is not an image"); // this isn't working
return false;
}
var fd = new FormData();
var f = $.canvasResize('dataURLtoBlob', data);
f.name = file.name;
fd.append($('input[name=photo]').attr('name'), f);
$.ajax({
url: 'doupload.php',
type: 'POST',
data: fd,
dataType: 'json',
contentType: false,
processData: false,
success: function() {
window.location.href = "http://www.stackoverflow.com"; // THIS ISN'T WORKING TOO
}
})
}
});
});
现在完成之后,我尝试在AJAX完成后重定向到另一个页面,但它无法正常工作,警报也无法正常工作。有什么想法吗?
答案 0 :(得分:0)
$.ajax({
url: 'doupload.php',
type: 'POST',
data: fd,
dataType: 'json',
contentType: false,
processData: false,
success: function() {
location.href = "http://www.stackoverflow.com";
},
error: function() {
//handle errors here
},
complete: function() {
// this code is always executed
location.href = "http://www.stackoverflow.com";
}
})
或者
var jqXHR = $.ajax({...
});
jqXHR.always(function(){
location.href = "http://www.stackoverflow.com";
})