Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ajax POST request doesn't work with HTTPS

Featured Replies

Hello all,

 

I've recently updated to HTTPS and I've found that my Ajax functions are not working. At first I got a CORS error message but I've managed to pick up a couple of lines of code from web forums that have had the same problem and the error message has changed to a 403 error message, (meaning that the file is forbidden), which is interesting as since upgrading to HTTPS my site sometimes can't find, or is not accessing some of my images and/or files.

 

Therefore it might be my .htaccess file, (I used to have a basic .htaccess file when the site was HTTP but I've had to google .htaccess with HTTPS). Here's my .htaccess file:

 

 

 
      Options +FollowSymLinks
RewriteEngine On
   RewriteCond %{HTTPS} off [OR]
   RewriteCond %{HTTP_HOST} !^www\. [OR]
   RewriteCond %{HTTP_HOST} ^mysite.com\.com$ [NC]
   RewriteRule ^ https://www.mysite.com%{REQUEST_URI} [R=301,L,NE]
   RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
   RewriteRule ^index\.php(/(.*))?$ mysite.com/$2 [R=301,L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule .* index.php/$0 [PT,L]
 

 

It's possible that this file is responsible for not allowing my site to access certain files and images. I've also added the snippet of my Ajax request here, (just in case there's something wrong with the function:

 

 

 
      $.ajax({
                        url: "/my_php_file/my_function",
                        crossDomain: true,
                        contentType: "application/x-www-form-urlencoded",
                        xhrFields: {
                            withCredentials: true
                        },
                        headers: {
                            'Access-Control-Allow-Origin': '*'
                        },
                        type: 'POST',
                        async:false,
                        data: data,
                        success: function(msg) {
                        
                          alert('success');
                                     
                        }
      });
 

 

I've tried adding the following and/or changing the following lines of code but it still doesn't work:

 

 

 
     url: "/my_php_file/my_function/",
     url: "https://www.mysite.com/my_php_file/my_function",
     dataType: 'jsonp',
     dataType: 'json',
     dataType: 'html',
 

 

The above lines are code I've added, (they've not been added all together), but it's just so everyone knows what different permutations I've tried. It's a good possibility that it's the .htaccess file as some of my images and files don't work, or both so can anyone can help out on both or either?

 

Thanks in advance.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.