2

Function .load doesn't work on Chrome on localhost (with Xampp).
On JsFiddle nothing happens if I run the button. My goal is on load to DIV id="lista_ogol" another page. Is it possible?
Thanks for every help, if my code is messy let me know what to change.

Here is my html code:

<ul>
    <div id="lista_ogol" class="lista">
    <li><a id="rejestracjaID" href="javascript:void(0)" >Rejestracja</a></li>
    <li><a href="logowanie.php">Logowanie</a></li>
    </div>
</ul>

Here is my Js script:

jQuery(function(){
            jQuery('#rejestracjaID').click(function(){
                jQuery('#lista_ogol').load('logowanie.php', 
                        function(){alert('Content Successfully Loaded.')} 
                );
            });
        })
Mike Quoro
  • 141
  • 1
  • 7
  • Can you please check your console logs and paste here? – Shreeram K Aug 02 '15 at 11:33
  • `Uncaught ReferenceError: jQuery is not defined` I'm sorry and I will delete this Question if it is too easy. I am just starting with coding – Mike Quoro Aug 02 '15 at 11:39
  • If below ans works, do not forget to mark it as "Answer" – Shreeram K Aug 02 '15 at 11:46
  • possible duplicate of [Uncaught ReferenceError: jQuery is not defined](http://stackoverflow.com/questions/8886614/uncaught-referenceerror-jquery-is-not-defined) – Gary Aug 02 '15 at 11:47
  • Thanks, still the code doesn't work propertly but it doesn't show any warnings. I had included the code in HEAD before, now i have it in body and Chrome finally see it – Mike Quoro Aug 02 '15 at 11:50

2 Answers2

2

You need to include jquery script in your html file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

Make sure you put this in the <head> of your document, or above the script you use to load the PHP page.

Nebula
  • 6,614
  • 4
  • 20
  • 40
Shreeram K
  • 1,719
  • 13
  • 22
2

If you aren't getting any jQuery related errors (like $ is not defined/jQuery is not defined), it means jQuery is working fine.


The first thing that comes into mind ending up in situations like this is that the requested page was not found. Try including the correct URL to the logowanie.php (e.g. "/gate/login/logowanie.php") as the .load() might not have been able to locate the file that you have requested.

Meanwhile, if you want to add any new html page into the DIV, an alternative (which may or may not serve your purpose) is to first echo out an iframe and then append it using .append() method of jQuery as such:

jQuery('#lista_ogol').append(<the iframe>);
Ahmad Baktash Hayeri
  • 5,802
  • 4
  • 30
  • 43