【问题标题】:In Ajax: any configuration difference between Nginx and Apache在 Ajax 中:Nginx 和 Apache 之间的任何配置差异
【发布时间】:2015-08-10 12:17:02
【问题描述】:

我将一个 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'); 

            }); 
        });
})();

【问题讨论】:

    标签: php jquery ajax apache nginx


    【解决方案1】:

    使用表单数据对象解决了这个问题!

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

    【讨论】:

      猜你喜欢
      • 2015-01-17
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多