Why not using Ajax form is submitted?

This code processes the form when submitting:

the <script>
 jQuery("form").submit(function() {
 var form_data = jQuery(this).serialize();
jQuery.ajax({
 type: "POST",
 url: "/form1.php",
 data: form_data,
 success: function(data) {
 alert("Accepted. We will contact you within 1 hour!");
}
});
 return false;
});
 </script>


However, when you try to submit the form in the console appears the error:
Mixed Content: The page at 'https://site.ru/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'site.ru:443'. This request has been blocked; the content must be served over HTTPS.


This error disappears if you remove the htaccess:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/robots\.txt
RewriteRule !(^$|.*\.(css|jpg|gif|ico|png)) / [R=301,L]

RewriteCond %{QUERY_STRING} ^(.+) [NC]
RewriteRule ^(.*)$ /$1? [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]


But I need this htaccess.
How to rewrite to allow using ajax to send form?
March 20th 20 at 11:32
1 answer
March 20th 20 at 11:34
Solution
RewriteRule !(^$|.*\.(css|jpg|gif|ico|png)) / [R=301,L]

This rule redirects to main all in pictures and styles, so that the request /form1.php will be processed by this rule.
You can add an exception for file RewriteCond %{REQUEST_URI} !^/form1\.php
Or for any POST requests RewriteCond %{REQUEST_METHOD} !POST
yay! thank you! - Velva.Gutkowski56 commented on March 20th 20 at 11:37

Find more questions by tags AJAXhtaccess