我将一个 php 应用程序从在 nginx(无 SSL)上运行的开发服务器移至在 Apache(有 SSL)上运行的共享托管服务器。
问题:当应用程序位于 nginx 服务器上时,站点的 JS 脚本(多个 JQuery Ajax 函数)经过全面测试并按预期工作。一旦迁移到在 Apache 上运行的生产服务器,带有“POST”方法的 Ajax 功能就停止工作了!
我的 .htaccess 文件如下所示:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
这是生产中的示例 header
Remote Address:ipAddress:443
Request URL:https://example.com/store/
Request Method:POST
Status Code:301 Moved Permanently
随后是对同一 URL http://example.com/store/ 的 Get 请求
同样的开发要求
Remote Address:ipAddress:80
Request URL:http://example.com/store/
Request Method:POST
Status Code:200 OK
我假设此问题是 Ajax 相关问题或服务器问题。这是我的 Ajax 函数
;(function(){
$('.create-store').click(function(){
$.ajax({
type : 'POST',
url: "/store/", // I also tried url : "https://www.example.com/store/"
data: $('form').serialize(),
beforeSend: function( xhr ) {
// add
},
error: function(data){
// handle error
},
success : function(data){
// handle success message
}
})
.done(function( data ) {
//alert('updated');
});
});
})();
最佳答案
使用表单数据对象解决了这个问题!
;(function(){
var formData = new FormData('form');
var method = formData.get('method');
$('.create-store').click(function(){
$.ajax({
type : method, //==POST!
url: "/store/", // I also tried url : "https://www.example.com/store/"
data: $('form').serialize(),
beforeSend: function( xhr ) {
// add
},
error: function(data){
// handle error
},
success : function(data){
// handle success message
}
})
.done(function( data ) {
//alert('updated');
});
});
})();
关于php - 在 Ajax : any configuration difference between Nginx and Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30498944/