php - 在 Ajax : any configuration difference between Nginx and Apache

标签 php jquery ajax apache nginx

我将一个 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/

相关文章:

jQuery 如何从提交按钮中选择所有输入字段

javascript - 如何在javascript中将列表设置为剑道网格数据源?

php - 根据所选有效期,在 1 个月或 3 个月后删除行

php - 使用 PHP 生成 NACHA 文件?

php - Tomcat应用访问问题

jquery - 如何将 jqGrid 与 ASP.NET MVC 结合使用?

php - 获取关系型 mysql 表中的外部 id

javascript - jQuery/ Ajax : How to send data to an url without showing data in web-developers

javascript - 在 PHP 后端访问 XMLHttpRequests send(data)

javascript - 使用ajax加载js内容时出现问题