• Resolved bonnerl17

    (@bonnerl17)


    What I’m doing is making the different sections in my sidebar collapsible. It would be working fine except that when my javascript calls sidebar_update.php to get the stuff it’s adding when they expand a section it doesn’t always return what’s actually in the file. Instead what it’s does the majority of the time is display the index.php as if I called a file that doesn’t exist and why it only does it some/most of the time doesn’t make sense.

    Here is the content of “sidebar_update.php”

    <?php
     require('wp-config.php') ;
    
      $pages_in=$_POST['pages_in'];
    
     if ($pages_in=="PR")
     { ?>
    <form method="post"><input type="hidden" id="pages_in" name="pages_in" value="PE" /></form>
         <h2 class="h2E" onclick="pages()"><?php _e('pages'); ?></h2>
         <ul class="SideLinksUL">
    <?php wp_list_pages('title_li='); ?>
         </ul>
    <?php } else {
      echo "error";
     }; ?>

    Here is the javascript though I don’t think the problem is with it… PS: in the interest of saving a little space I left out most of the XMLHttpRequest detecting stuff out.

    function pages()
    
    {
    xmlHttp=GetXmlHttpObject()
    
    if (xmlHttp==null)
    
     {
    
     alert ("Browser does not support HTTP Request")
    
     return
    
     }
      var pages_in=document.getElementById("pages_in");
      var retract=('<form method="get"><input type="hidden" id="pages_in" name="pages_in" value="PR" /></form> <h2 class="h2R" onclick="pages()">pages</h2>');
      if (pages_in.value=="PR")
      {
      var url="sidebar_update.php";
      url=url+"&sid="+Math.random();
      var params="pages_in=" + pages_in.value;
      xmlHttp.onreadystatechange=stateChangedS1;
      xmlHttp.open("POST",url,true);
      xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-Length", params.length);
      xmlHttp.send(params);
      } else if (pages_in.value=="PE") {
       document.getElementById("pages").innerHTML=retract;
    
      }
    }
    
    function stateChangedS1()
    
    { 
    
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    
     {
    
     document.getElementById("pages").innerHTML=xmlHttp.responseText
    
     }
    
    }

    Just so you know in the sidebar.php page under the theme folder I’m using “<script type=”text/javascript”></script>” to get the javascript from the main w-p directory since I can’t have the “sidebar_update.php” page in the theme folder.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter bonnerl17

    (@bonnerl17)

    Still having the same problem and seeing as to how my post has been moved back a page I’m bumping it. ??

    Here’s a recap of my issue: I’m using javascript to make the sections in my sidebar retractable. When the javascript sends info to “sidebar_update.php”.”Sidebar_update.php” then should be receiving some information from the javascript to confirm what it (the sidebar_update.php) should send back to the javascript to display. But the javascript 99% of the time displays the index.php as if it didn’t find “sidebar_update.php”.

    See above post for the contents of “sidebar_update.php” as well as the javascript.

    Thread Starter bonnerl17

    (@bonnerl17)

    Last intentional bump I’m doing, cause I hate bumping, but I have a problem and no answer.

    Is there anyone at least looking into this for me?

    Is the problem I’m having a bug, that I should report?

    Thanks for any input/help you might provide…

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Mmm… I’m not entirely certain what the issue is, however you should not have this line in the PHP code:
    require('wp-config.php');

    That will work for some limited cases, but saying which cases is a bit tricky. It will often cause errors. Changing it to this will always work:
    require('wp-blog-header.php');

    That’s the right way to include WordPress’ functionality (without including the whole blog).

    Also, does hitting the sidebar_update.php directly from a browser return the correct results? If it’s showing the whole blog at index.php (or redirecting) what’s the contents of the .htaccess file?

    Thread Starter bonnerl17

    (@bonnerl17)

    Mmm… I’m not entirely certain what the issue is, however you should not have this line in the PHP code:
    require(‘wp-config.php’);

    That will work for some limited cases, but saying which cases is a bit tricky. It will often cause errors. Changing it to this will always work:
    require(‘wp-blog-header.php’);

    Ok, thanks.

    Also, does hitting the sidebar_update.php directly from a browser return the correct results?

    Yes it works correctly when you access it directly.

    If it’s showing the whole blog at index.php (or redirecting) what’s the contents of the .htaccess file?

    Options All -Indexes

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    That’s what’s in both .htaccess. The reason I say both is because I’ve got my WP home page set to “www.example.com” and WP in “www.example.com/blog/”.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    var url="sidebar_update.php";

    That’s wrong, I think. Try using the complete URL path instead of a relative path. Especially if you’re using pretty permalinks.

    A relative path is relative to the current page. If the current page is https://example.com/blog/ then the above will get https://example.com/blog/sidebar_update.php. However, if you’re looking at https://example.com/blog/some-post-name/, then the above will get https://example.com/blog/some-post-name/sidebar_update.php, which does not exist. See?

    Alternatively, add a / in front of sidebar_update.php in that same code. That will force it to go to the root. Still, a complete http URL will be better.

    Thread Starter bonnerl17

    (@bonnerl17)

    Yep that would make sense. But using the complete url didn’t help. I don’t think it I should be lacking anything but at the moment I’m running this of my test server on my computer. So I don’t know if it’s possible that I’m lacking anything, but I do know I have “mod_rewrite” actively going.

    Note: I am using fancy permalinks…

    Thread Starter bonnerl17

    (@bonnerl17)

    Problem solved.

    Ok so I discovered my problem was were I had a line in the javascript to prevent it for cacheing the results of “sidebar_update.php” and the line was

    // url=url+”&sid=”+Math.random();

    I also fixed a the line that had the info to send to the sidebar_update page, so that it is now.

    var params=”pages_in=” + pages_in.value + “&auth=” + auth;

    Thanks for your help Otto42.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘it’s redirecting… why?’ is closed to new replies.