admin-ajax.php mixed content

admin2025-06-02  1

Cant access admin-ajax from https. In my js i wrote

$.ajax({
    url: 'https://'+window.location.host+'/admin/admin-ajax.php',
    type:'post',
    data:'action=bid_now_live_me&_pid='+ mypid ,
    success: function (data) {  

So I changed every url to https but still no luck. In chrome network I get

In console just lot's of errors

Tried to force ssl by modifing my htaccess, wp-config and by using force ssl plugin. And of course I tried to disable all plugins.

Cant access admin-ajax from https. In my js i wrote

$.ajax({
    url: 'https://'+window.location.host+'/admin/admin-ajax.php',
    type:'post',
    data:'action=bid_now_live_me&_pid='+ mypid ,
    success: function (data) {  

So I changed every url to https but still no luck. In chrome network I get

In console just lot's of errors

Tried to force ssl by modifing my htaccess, wp-config and by using force ssl plugin. And of course I tried to disable all plugins.

Share Improve this question edited Mar 6, 2019 at 17:29 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Mar 6, 2019 at 17:19 Ivan KovalevIvan Kovalev 213 bronze badges 1
  • Problem resolved by moving my site to different hosting, dont know why, but it works fine on digitalocean. Forgot to mention, this problem was only when I used https, the whole site worked fine exept this one admin-ajax, on http admin-ajax worked fine. – Ivan Kovalev Commented Mar 7, 2019 at 18:03
Add a comment  | 

2 Answers 2

Reset to default 1

You shouldn't do something like this in your JS code:

url: 'https://'+window.location.host+'/admin/admin-ajax.php',

You should use wp_localize_script and pass proper URL in there.

Let's say your AJAX call is located in file my-js-file.js. Somewhere in your theme/plugin you have something like this

wp_enqueue_script( '<SOME_HANDLE>', ... . 'my-js-file.js' , ...);

You should add this after it:

wp_localize_script( '<SOME_HANDLE>', 'MyScriptData', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

And in your JS file it should be

$.ajax({
    url: MyScriptData.ajax_url,
    type:'post',

for a default Wordpress installation,

url: 'https://'+window.location.host+'/admin/admin-ajax.php',

should be

    url: 'https://'+window.location.host+'/wp-admin/admin-ajax.php',

i.e /admin/ should be /wp-admin/.
I hope this helps.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748832368a314095.html

最新回复(0)