繁体   English   中英

jQuery上传不适用于使用重写的URL的页面

[英]JQuery upload doesn't work with page using a rewritten url

我发现了一个带有进度条的php jquery上传脚本,它实际上有效。

问题是,如果我使用apache mod rewrite将URL从http://www.mysite.com/upload.php重写为http://www.mysite.com/uploads/upload.php ,它将无法正常工作但如果我使用未重写的网址,它将起作用

jQuery无法在重写的URL上运行是否有原因?

它不使用jquery表单来取消上载,而只是执行常规上载。

这是upload.php的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Upload and Resize with jQuery and PHP</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
 <script> 
        $(document).ready(function() { 
        //elements
        var progressbox     = $('#progressbox');
        var progressbar     = $('#progressbar');
        var statustxt       = $('#statustxt');
        var submitbutton    = $("#SubmitButton");
        var myform          = $("#UploadForm");
        var output          = $("#output");
        var completed       = '0%';

                $(myform).ajaxForm({
                    beforeSend: function() { //brfore sending form
                        submitbutton.attr('disabled', ''); // disable upload button
                        statustxt.empty();
                        progressbox.slideDown(); //show progressbar
                        progressbar.width(completed); //initial value 0% of progressbar
                        statustxt.html(completed); //set status text
                        statustxt.css('color','#000'); //initial color of status text
                    },
                    uploadProgress: function(event, position, total, percentComplete) { //on progress
                        progressbar.width(percentComplete + '%') //update progressbar percent complete
                        statustxt.html(percentComplete + '%'); //update status text
                        if(percentComplete>50)
                            {
                                statustxt.css('color','#fff'); //change status text to white after 50%
                            }
                        },
                    complete: function(response) { // on complete
                        output.html(response.responseText); //update element with received data
                        myform.resetForm();  // reset form
                        submitbutton.removeAttr('disabled'); //enable submit button
                        progressbox.slideUp(); // hide progressbar
                    }
            });
        }); 

    </script> 
 <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<form action="processupload.php" method="post" enctype="multipart/form-data" id="UploadForm">
<table width="500" border="0">
  <tr>
    <td>File : </td>
    <td><input name="ImageFile" type="file" /></td>
  </tr>

  <tr>
    <td>&nbsp;</td>
    <td><input type="submit"  id="SubmitButton" value="Upload" /></td>
  </tr>
</table>
</form>

<div id="progressbox"><div id="progressbar"></div ><div id="statustxt">0%</div ></div>
<div id="output"></div>


</body>
</html>

编辑:

附加的htaccess(精简版)

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /

RewriteRule ^admin$ admin/ [R,L]

# Admin rewrite rules
RewriteRule ^/?admin/$ admin/index.php [NC,L]
RewriteRule ^/?admin/news$ /admin/news.php [NC,L]
RewriteRule ^/?admin/uploads/upload$ /admin/upload.php [NC,L]

我的猜测是罪魁祸首是缺少目标页面( <form>动作所指向的页面)。

可能是在uploads/processupload.php (使用重写时)在processupload.php寻找它。

您probalby忘记为processupload.php重写,但是直到您发布.htaccess文件后我才能确定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM