我使用下面的代码将文件上传到在线测试服务器(http://posttestserver.com/post.php),它已成功上传,并且代码也按要求正常工作,但问题在于I必须将文件上传到内部PHP服务器,即https://xxxx.xxxx.xxxxx.com/sites/default/files/FileUpload/upload_file.php,该代码不适用于下面的代码,而如果我删除了ajax,进度条和脚本部分,并且只使用表单标记运行代码,则它可以上传文件。使用ajax文件上传到PHP服务器不起作用
请帮我我无法跟踪这个问题,我没有在PHP知识。
同样在下面的错误日志中找到评论。
<!DOCTYPE html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<style>
form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; padding: 15px }
#progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
#bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
#percent { position:absolute; display:inline-block; top:3px; left:48%; }
</style>
</head>
<body>
<h1>Ajax File Upload Demo</h1>
<form id="myForm" action="http://posttestserver.com/post.php" method="post" enctype="multipart/form-data">
<input type="file" size="60" name="file">
<input type="submit" value="Ajax File Upload">
</form>
<div id="progress">
<div id="bar"></div>
<div id="percent">0%</div >
</div>
<br/>
<div id="message"></div>
<script>
$(document).ready(function()
{
var options = {
beforeSend: function()
{
$("#progress").show();
$("#bar").width('0%');
$("#message").html("");
$("#percent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$("#bar").width(percentComplete+'%');
$("#percent").html(percentComplete+'%');
},
success: function()
{
$("#bar").width('100%');
$("#percent").html('100%');
},
complete: function(response)
{
$("#message").html("<font color='green'>"+response.responseText+"</font>");
},
error: function()
{
$("#message").html("<font color='red'> ERROR: unable to upload files</font>");
}
};
$("#myForm").ajaxForm(options);
});
</script>
</body>
</html>
请人给我的问题,其真正的紧急应对 – Music
错误日志--- XMLHttpRequest无法加载https://xxxx.xxx.xxxxx.com/sites/default/files/FileUpload/upload_file.php。该请求被重定向到'https://xxxxxxxx-xxx-xxxx.xxxx.com/adfs/ls/?wa=wsignin1.0&wtrealm=h...%252ffiles%252fFileUpload%252fupload_file.php&wct=2014-02-11T12%3a02% 3a23Z',它不允许需要预检的跨源请求。 – Music