2014-02-11 108 views
1

我使用下面的代碼將文件上傳到在線測試服務器(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> 
+0

請人給我的問題,其真正的緊急應對 – Music

+0

錯誤日誌--- 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

回答