Why does my href only work after I manually refresh the page?












3














I made a table filled with SQL data. I added a data-href to the table rows, which brings me to another page and shows all the data from that row. But this only works after I manually refresh the page my table is on. When I enter the page using normal hrefs, clicking the table row doesn't do anything. When I refresh my page using the page refresher next to the URL bar, the table row event works. What is the cause of this?



<script>
var trid;
function foo() {
}
</script>
<script>
$(function(){
$('*[data-href]').click(function(){
window.location = $(this).data('href');
return false;
});
});
</script>


This code above is located in the page head



<div data-role="navbar">
<ul>
<li><a href="stoftest.php">Stoftest</a></li>
<li><a href="overzicht.php">Overzicht</a></li>
<li><a href="klim.php">Klimopdracht</a></li>
</ul>
</div>


Code above is the reference to the page with the table (middle one).



echo "<table>"; 
echo "<tr>";
echo "<th>".'Stof'."</th>";
echo "<th>".'Score'."</th>";
echo "<th>".'Datum'."</th>";
echo "</tr>";
foreach ($result as $pers) {
echo "<tr data-href='detail.php?persId=".$pers->id."'>";
echo "<td>".$pers->stofid."</td>
<td>".$pers->zoeken."</td>
<td>".$pers->datum."</td>";
echo "</tr>";
}
echo "</table>";


Code above is my table using PHP and HTML



All of this only works after a manual page refresh. I have no clue what causes this problem. I even tried a automatic page refresh when I enter this page, but this refresh event only works after I manually refresh the page.



Tell me if you need any more code.










share|improve this question
























  • better use a class, and call .classname.on click, on works like live,
    – Ahmed Sunny
    Nov 19 '18 at 12:27










  • Perhaps the page is caching. If you're using chrome try ensuring you have cache disabled in network tab of the developer tools or go into "incognito mode" and see if the error still persists.
    – Nick Parsons
    Nov 19 '18 at 12:29










  • the error still persists, i tried incognito mode
    – Jop Rill
    Nov 19 '18 at 12:31








  • 2




    Duplicate of your own previous question, stackoverflow.com/questions/53370503 Please do not create such duplicates, but follow up on the responses you get to your original version of the question. (And if those don’t come immediately, then show a bit of patience!) If you have relevant new info to add, then please edit your existing question, instead of creating a new one.
    – misorude
    Nov 19 '18 at 13:37








  • 1




    Possible duplicate of My table row action doesnt work unless I manually refresh the page. How to fix this?
    – ADyson
    Nov 19 '18 at 13:47
















3














I made a table filled with SQL data. I added a data-href to the table rows, which brings me to another page and shows all the data from that row. But this only works after I manually refresh the page my table is on. When I enter the page using normal hrefs, clicking the table row doesn't do anything. When I refresh my page using the page refresher next to the URL bar, the table row event works. What is the cause of this?



<script>
var trid;
function foo() {
}
</script>
<script>
$(function(){
$('*[data-href]').click(function(){
window.location = $(this).data('href');
return false;
});
});
</script>


This code above is located in the page head



<div data-role="navbar">
<ul>
<li><a href="stoftest.php">Stoftest</a></li>
<li><a href="overzicht.php">Overzicht</a></li>
<li><a href="klim.php">Klimopdracht</a></li>
</ul>
</div>


Code above is the reference to the page with the table (middle one).



echo "<table>"; 
echo "<tr>";
echo "<th>".'Stof'."</th>";
echo "<th>".'Score'."</th>";
echo "<th>".'Datum'."</th>";
echo "</tr>";
foreach ($result as $pers) {
echo "<tr data-href='detail.php?persId=".$pers->id."'>";
echo "<td>".$pers->stofid."</td>
<td>".$pers->zoeken."</td>
<td>".$pers->datum."</td>";
echo "</tr>";
}
echo "</table>";


Code above is my table using PHP and HTML



All of this only works after a manual page refresh. I have no clue what causes this problem. I even tried a automatic page refresh when I enter this page, but this refresh event only works after I manually refresh the page.



Tell me if you need any more code.










share|improve this question
























  • better use a class, and call .classname.on click, on works like live,
    – Ahmed Sunny
    Nov 19 '18 at 12:27










  • Perhaps the page is caching. If you're using chrome try ensuring you have cache disabled in network tab of the developer tools or go into "incognito mode" and see if the error still persists.
    – Nick Parsons
    Nov 19 '18 at 12:29










  • the error still persists, i tried incognito mode
    – Jop Rill
    Nov 19 '18 at 12:31








  • 2




    Duplicate of your own previous question, stackoverflow.com/questions/53370503 Please do not create such duplicates, but follow up on the responses you get to your original version of the question. (And if those don’t come immediately, then show a bit of patience!) If you have relevant new info to add, then please edit your existing question, instead of creating a new one.
    – misorude
    Nov 19 '18 at 13:37








  • 1




    Possible duplicate of My table row action doesnt work unless I manually refresh the page. How to fix this?
    – ADyson
    Nov 19 '18 at 13:47














3












3








3







I made a table filled with SQL data. I added a data-href to the table rows, which brings me to another page and shows all the data from that row. But this only works after I manually refresh the page my table is on. When I enter the page using normal hrefs, clicking the table row doesn't do anything. When I refresh my page using the page refresher next to the URL bar, the table row event works. What is the cause of this?



<script>
var trid;
function foo() {
}
</script>
<script>
$(function(){
$('*[data-href]').click(function(){
window.location = $(this).data('href');
return false;
});
});
</script>


This code above is located in the page head



<div data-role="navbar">
<ul>
<li><a href="stoftest.php">Stoftest</a></li>
<li><a href="overzicht.php">Overzicht</a></li>
<li><a href="klim.php">Klimopdracht</a></li>
</ul>
</div>


Code above is the reference to the page with the table (middle one).



echo "<table>"; 
echo "<tr>";
echo "<th>".'Stof'."</th>";
echo "<th>".'Score'."</th>";
echo "<th>".'Datum'."</th>";
echo "</tr>";
foreach ($result as $pers) {
echo "<tr data-href='detail.php?persId=".$pers->id."'>";
echo "<td>".$pers->stofid."</td>
<td>".$pers->zoeken."</td>
<td>".$pers->datum."</td>";
echo "</tr>";
}
echo "</table>";


Code above is my table using PHP and HTML



All of this only works after a manual page refresh. I have no clue what causes this problem. I even tried a automatic page refresh when I enter this page, but this refresh event only works after I manually refresh the page.



Tell me if you need any more code.










share|improve this question















I made a table filled with SQL data. I added a data-href to the table rows, which brings me to another page and shows all the data from that row. But this only works after I manually refresh the page my table is on. When I enter the page using normal hrefs, clicking the table row doesn't do anything. When I refresh my page using the page refresher next to the URL bar, the table row event works. What is the cause of this?



<script>
var trid;
function foo() {
}
</script>
<script>
$(function(){
$('*[data-href]').click(function(){
window.location = $(this).data('href');
return false;
});
});
</script>


This code above is located in the page head



<div data-role="navbar">
<ul>
<li><a href="stoftest.php">Stoftest</a></li>
<li><a href="overzicht.php">Overzicht</a></li>
<li><a href="klim.php">Klimopdracht</a></li>
</ul>
</div>


Code above is the reference to the page with the table (middle one).



echo "<table>"; 
echo "<tr>";
echo "<th>".'Stof'."</th>";
echo "<th>".'Score'."</th>";
echo "<th>".'Datum'."</th>";
echo "</tr>";
foreach ($result as $pers) {
echo "<tr data-href='detail.php?persId=".$pers->id."'>";
echo "<td>".$pers->stofid."</td>
<td>".$pers->zoeken."</td>
<td>".$pers->datum."</td>";
echo "</tr>";
}
echo "</table>";


Code above is my table using PHP and HTML



All of this only works after a manual page refresh. I have no clue what causes this problem. I even tried a automatic page refresh when I enter this page, but this refresh event only works after I manually refresh the page.



Tell me if you need any more code.







javascript php html-table






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:31









Nesku

318111




318111










asked Nov 19 '18 at 12:21









Jop Rill

327




327












  • better use a class, and call .classname.on click, on works like live,
    – Ahmed Sunny
    Nov 19 '18 at 12:27










  • Perhaps the page is caching. If you're using chrome try ensuring you have cache disabled in network tab of the developer tools or go into "incognito mode" and see if the error still persists.
    – Nick Parsons
    Nov 19 '18 at 12:29










  • the error still persists, i tried incognito mode
    – Jop Rill
    Nov 19 '18 at 12:31








  • 2




    Duplicate of your own previous question, stackoverflow.com/questions/53370503 Please do not create such duplicates, but follow up on the responses you get to your original version of the question. (And if those don’t come immediately, then show a bit of patience!) If you have relevant new info to add, then please edit your existing question, instead of creating a new one.
    – misorude
    Nov 19 '18 at 13:37








  • 1




    Possible duplicate of My table row action doesnt work unless I manually refresh the page. How to fix this?
    – ADyson
    Nov 19 '18 at 13:47


















  • better use a class, and call .classname.on click, on works like live,
    – Ahmed Sunny
    Nov 19 '18 at 12:27










  • Perhaps the page is caching. If you're using chrome try ensuring you have cache disabled in network tab of the developer tools or go into "incognito mode" and see if the error still persists.
    – Nick Parsons
    Nov 19 '18 at 12:29










  • the error still persists, i tried incognito mode
    – Jop Rill
    Nov 19 '18 at 12:31








  • 2




    Duplicate of your own previous question, stackoverflow.com/questions/53370503 Please do not create such duplicates, but follow up on the responses you get to your original version of the question. (And if those don’t come immediately, then show a bit of patience!) If you have relevant new info to add, then please edit your existing question, instead of creating a new one.
    – misorude
    Nov 19 '18 at 13:37








  • 1




    Possible duplicate of My table row action doesnt work unless I manually refresh the page. How to fix this?
    – ADyson
    Nov 19 '18 at 13:47
















better use a class, and call .classname.on click, on works like live,
– Ahmed Sunny
Nov 19 '18 at 12:27




better use a class, and call .classname.on click, on works like live,
– Ahmed Sunny
Nov 19 '18 at 12:27












Perhaps the page is caching. If you're using chrome try ensuring you have cache disabled in network tab of the developer tools or go into "incognito mode" and see if the error still persists.
– Nick Parsons
Nov 19 '18 at 12:29




Perhaps the page is caching. If you're using chrome try ensuring you have cache disabled in network tab of the developer tools or go into "incognito mode" and see if the error still persists.
– Nick Parsons
Nov 19 '18 at 12:29












the error still persists, i tried incognito mode
– Jop Rill
Nov 19 '18 at 12:31






the error still persists, i tried incognito mode
– Jop Rill
Nov 19 '18 at 12:31






2




2




Duplicate of your own previous question, stackoverflow.com/questions/53370503 Please do not create such duplicates, but follow up on the responses you get to your original version of the question. (And if those don’t come immediately, then show a bit of patience!) If you have relevant new info to add, then please edit your existing question, instead of creating a new one.
– misorude
Nov 19 '18 at 13:37






Duplicate of your own previous question, stackoverflow.com/questions/53370503 Please do not create such duplicates, but follow up on the responses you get to your original version of the question. (And if those don’t come immediately, then show a bit of patience!) If you have relevant new info to add, then please edit your existing question, instead of creating a new one.
– misorude
Nov 19 '18 at 13:37






1




1




Possible duplicate of My table row action doesnt work unless I manually refresh the page. How to fix this?
– ADyson
Nov 19 '18 at 13:47




Possible duplicate of My table row action doesnt work unless I manually refresh the page. How to fix this?
– ADyson
Nov 19 '18 at 13:47












1 Answer
1






active

oldest

votes


















0














Your click handler is fine so the issue must lie elsewhere in the page.



Opening your Javascript console and adding some console.log calls can be helpful. e.g.



$('*[data-href]')
.each(function()
{
// Check this value the first time the page loads
// then see if it changes when the page reloads
console.log($(this).data('href'));
})
.click(function(event)
{
event.preventDefault();
window.location = $(this).data('href');
});





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374534%2fwhy-does-my-href-only-work-after-i-manually-refresh-the-page%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your click handler is fine so the issue must lie elsewhere in the page.



    Opening your Javascript console and adding some console.log calls can be helpful. e.g.



    $('*[data-href]')
    .each(function()
    {
    // Check this value the first time the page loads
    // then see if it changes when the page reloads
    console.log($(this).data('href'));
    })
    .click(function(event)
    {
    event.preventDefault();
    window.location = $(this).data('href');
    });





    share|improve this answer


























      0














      Your click handler is fine so the issue must lie elsewhere in the page.



      Opening your Javascript console and adding some console.log calls can be helpful. e.g.



      $('*[data-href]')
      .each(function()
      {
      // Check this value the first time the page loads
      // then see if it changes when the page reloads
      console.log($(this).data('href'));
      })
      .click(function(event)
      {
      event.preventDefault();
      window.location = $(this).data('href');
      });





      share|improve this answer
























        0












        0








        0






        Your click handler is fine so the issue must lie elsewhere in the page.



        Opening your Javascript console and adding some console.log calls can be helpful. e.g.



        $('*[data-href]')
        .each(function()
        {
        // Check this value the first time the page loads
        // then see if it changes when the page reloads
        console.log($(this).data('href'));
        })
        .click(function(event)
        {
        event.preventDefault();
        window.location = $(this).data('href');
        });





        share|improve this answer












        Your click handler is fine so the issue must lie elsewhere in the page.



        Opening your Javascript console and adding some console.log calls can be helpful. e.g.



        $('*[data-href]')
        .each(function()
        {
        // Check this value the first time the page loads
        // then see if it changes when the page reloads
        console.log($(this).data('href'));
        })
        .click(function(event)
        {
        event.preventDefault();
        window.location = $(this).data('href');
        });






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 15:00









        Trent Reimer

        16




        16






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374534%2fwhy-does-my-href-only-work-after-i-manually-refresh-the-page%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules