Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hudolejev

    (@hudolejev)

    Finally found the root of the problem.

    My wp-admin is working via HTTPS. When I try to edit or delete questions in

    wp-admin / Settings / DS_FAQ

    I get the ‘Ajax Error 5’ mentioned above, and the following line being logged to JS console:

    XMLHttpRequest cannot load http://foo.bar/wp-content/plugins/wp-ds-faq/ajax.php. Origin https://foo.bar is not allowed by Access-Control-Allow-Origin.

    This thread on StackOverflow has some details, I won’t copy them here, just go and read there if interested.

    The fix is very simple. My modifications of wp-content/plugins/wp-ds-faq/ajax.php are below.

    Before:

    <?php
    require_once(preg_replace('|wp-content.*$|','', __FILE__) . 'wp-config.php');
    
    header('Content-type: text/javascript; charset='.get_settings('blog_charset'), true);
    header('Cache-control: max-age=2600000, must-revalidate', true);
    
    function error(){ die( "alert('Что-то не заработало :(')" ); }
    
    /* ... */

    After:

    <?php
    require_once(preg_replace('|wp-content.*$|','', __FILE__) . 'wp-config.php');
    
    header('Content-type: text/javascript; charset='.get_settings('blog_charset'), true);
    header('Cache-control: max-age=2600000, must-revalidate', true);
    header('Access-Control-Allow-Origin: '.get_site_url());
    header('Access-Control-Allow-Origin: '.str_replace('http://', 'https://', get_site_url()));
    
    function error(){ die( "alert('Что-то не заработало :(')" ); }
    
    /* ... */

    Two header('Access-Control-Allow-Origin') lines added, that’s it.

    Enjoy.

    Thread Starter hudolejev

    (@hudolejev)

    In case they delete my code again, here it is:

    http://codepad.org/vAZvehl3

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: WP DS FAQ] Failed to edit question’ is closed to new replies.