Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: pull variable from href

  1. #11
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by ggalan View Post
    would i need this on top?
    Code:
    $id = $_GET['id'];
    In a PHP code block, yes. And with error checking via isset() if your server requires that. Most are not that strict.

    Quote Originally Posted by ggalan View Post
    i tried placing the "?id=1" before the hash and now the whole thing doesnt work. any suggestions on how to make that "switch.php" page dynamic?
    Quote Originally Posted by ggalan View Post
    since the url is unique, can i write a condition based on the changing url? how would one do that??
    To diagnose the javascript part of it, I would need a link to the live page. However, even at that it would be time consuming to mock up because of the AJAX involved. To fix up the PHP part, I would need to see all of the PHP code employed.

    And I only have a vague idea of you objective here. It would help if you could be more clear on that.

    You might not need so much code. I get the feeling that you might be over complicating things. Like if you want to use AJAX, let it do most of the work and use less PHP and normal HTML. Or perhaps consider doing it all via PHP.

    One thing I did say is that if the link doesn't fire (often the case where javascript is involved), it won't matter if the query string is valid or not, at least insofar as what would normally happen in PHP and HTML on the page.

    This from my earlier post however does work:

    PHP Code:
    <?php 
    if(isset($_GET['bob'])){ 
        echo 
    $_GET['bob']; 

    ?> 
    <a href="?bob=Fred's Friend#/work/page1">GoTo /work/page1</a> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <a name="/work/page1">/work/page1</a>
    and answers your original question.

    I might add that if the javascript code relied upon an invalid query string in order to parse the link, of course it will no longer work if you change it to a valid one.

    Another thing I didn't mention before because it's unclear to me what your $.ajax() function is doing is that it appears perhaps to be a POST request. If so, the query string (GET data), even if valid (perhaps especially if valid), might not get passed to the requested page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. #12
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    thank you for all the communication, after all of this i think what i need is something like this
    http://www.stoimen.com/blog/2009/04/...-url-with-php/

    however this posts method doesnt seem to work, i will post files and if you have a moment, would be greatly appreciated

  3. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I have serious doubts about that method's applicability in this and pretty much any situation. You cannot call it via AJAX to get the value because the javascript on it cannot be used under an AJAX request, it requires a reload of the page so sort of defeats the purpose of doing anything unobtrusively, because it's using the hash, many requests to it will not be passed to the server anyway, and owing to its reliance upon cookies adds layers of uncertainty as to whether or not it will perform as expected.

    That said, it doesn't work even as stated on the page because the code is written using invalid characters and is poorly thought out as well. If it would be of any help, here's a working version:

    PHP Code:
    <script type="text/javascript">
        (function(){
            var h = location.hash;
            h = h.substring(h.indexOf('#') + 1);
            document.cookie = 'anchor=' + h;
        <?php
            $c 
    = isset($_COOKIE['anchor'])? $_COOKIE['anchor'] : '';
            
    $c "'" $c "'";
        
    ?>
            if(h !== <?php echo $c?>){
                location.reload();
            }
        })();
    </script>
    <?php
        $c 
    = isset($_COOKIE['anchor'])? $_COOKIE['anchor'] : '';
        echo 
    $c;
    ?>
    Perhaps if you ran it in a hidden iframe . . . But then there would be caching issues added to those already mentioned. These could perhaps be worked around, and then timing would become critical as to when this value became accessible to the rest of your code, still not solving many of the other issues.

    But I would strongly advise you to use a GET request with a valid query string for this, it would be so much simpler.
    Last edited by jscheuer1; 09-24-2010 at 12:14 AM. Reason: add detail, spelling
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #14
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    thank you for all the help, will go over all the notes this evening.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •