简体   繁体   中英

Why isn't JQuery echoing in my PHP code?

When a form titled "functions_question2" is submitted, the following PHP code should dictate what happens

<?php
if (isset($_POST['functions_question2'])) {
    if ($id) {
        $res3 = $db->query("SELECT * FROM answers WHERE user_id=$id");
        $data3 = $res3->fetch_array();
        if (isset($_SESSION['functions_question2']) && $_POST['functions_question2'] == $_SESSION['functions_question2']) {  
          if ($data3['FunctionsPercent'] > 50 && $data3['FunctionsPercent'] < 100) {
            $db->query("UPDATE answers SET FunctionsPercent = 50 WHERE user_id=$id");
            echo'<script type="text/javascript" src="insert.js"></script>'; 
            //***THIS IS THE PART THAT'S GIVING ME TROUBLE.
          }
        }
    }
}
?>

Within the external page insert.js, I have the following code:

<script type='text/javascript'>
$(document).ready(function(){
 $(".incorrectanswermark").fadeIn('slow');
});
</script>

All of the rest of the PHP executes correctly (the MySQL database updates), and there are no console errors. Also, I double-checked to make sure the div that's supposed to show up when the form submits does indeed have the class incorrectanswermark .

Any help would be much appreciated. Thanks!

Pursuant to the comment from @dan08 above, the script tags in your Javascript file are likely causing the failure.

Change:

<script type='text/javascript'>
$(document).ready(function(){
 $(".incorrectanswermark").fadeIn('slow');
});
</script>

To:

$(document).ready(function(){
 $(".incorrectanswermark").fadeIn('slow');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM