skip to Main Content

I Have two pages that I created a simple code with jquery and php

1st page

<?php
if(!defined("link")){
exit("hata");

}
?>

And second page

<?php
define("link",true);
?>
<script>
$("#load").load("sayfa.php");
</script>

Why first page is not working on second page using jquery?

2

Answers


  1. Based on my understanding the expectation was that since you have defined the link in the second file when you run the load command it will not print hata and be treated like it was defined.

    Basically, all the PHP code is run on the server side and any variables are destroyed once the PHP execution is completed and just the values get utilized by the HTML/JS page that is created.

    Since the sayfa.php (first) page is being loaded by javascript it is safe to assume that all PHP variables have already been removed by that point including the define.

    Check this question for reference and how variables can be used if needed.

    Jquery load() and PHP variables

    Login or Signup to reply.
  2. I think Your problem depends on how to show data in your file sayfa.php (print, echo etc, ex: print "hata";)
    Then the loading function will work correctly

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search