Forums

WP DS FAQ
Failed to edit question (3 posts)

  1. hudolejev
    Member
    Posted 1 year ago #

    Ajax error. [Error id: 5]

    Whatever that means

    http://wordpress.org/extend/plugins/wp-ds-faq/

  2. hudolejev
    Member
    Posted 1 year ago #

    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.

  3. hudolejev
    Member
    Posted 1 year ago #

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

    http://codepad.org/vAZvehl3

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags