简体   繁体   中英

In Ajax: any configuration difference between Nginx and Apache

I moved a php application from my development server which runs on nginx (no SSL) to a shared hosting server which runs on Apache ( with SSL ).

The problem : The site's JS scripts ( multiple JQuery Ajax functions ) was fully tested and worked as intended while the application was on the nginx server. Once migrated to the production server which run on Apache, Ajax function with "POST" method stopped working!

My .htaccess file looks like this:

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

Here is an example Headers from production

Remote Address:ipAddress:443
Request URL:https://example.com/store/
Request Method:POST
Status Code:301 Moved Permanently

And it is followed by a Get request for the same URL http://example.com/store/

The same exact request on development

Remote Address:ipAddress:80
Request URL:http://example.com/store/
Request Method:POST
Status Code:200 OK

I am assuming this issue is either an Ajax related issue or a server issue. so here is my Ajax function

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

            }); 
        });
})();

Using form data object solved the issue!

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

        }); 
    });
})();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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