2

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

enter image description here

In console just lot's of errors

enter image description here

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.

  • 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 Mar 7 '19 at 18:03
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',
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.