繁体   English   中英

在Ajax中:Nginx和Apache之间的任何配置差异

[英]In Ajax: any configuration difference between Nginx and Apache

我将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>

这是生产示例头

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'); 

        }); 
    });
})();

暂无
暂无

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

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