1

I'm trying to load an external php file via jquery into a specific div on my index page, but nothing will appear whatsoever.

This is my jquery script in the head

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
$(document).ready(function (){
    $("#content").load("index_content.php");
});
</script>

And of course the div is simply called on the page as <div id="content"></div>

My external php file is nothing special, it's just a table with lots of HTML and a few

<?php someFunctionCall(); ?>

No matter what I do, the content from the index_content.php will not load into the page when I load the site

Thanks

Phil
  • 157,677
  • 23
  • 242
  • 245
Jay
  • 161
  • 8
  • 1
    Check your browser's console; are there any errors? Can you see the AJAX `GET` request for `index_content.php` in the _Network_ console tab? What does the response look like? Hint: screenshots of your browser console can help get an answer quicker – Phil Jan 09 '19 at 01:52
  • Look at your developer console and enable error reporting for the PHP. – Funk Forty Niner Jan 09 '19 at 01:53
  • 2
    Ah never mind, I see the issue. See the duplicate link. Next time check your console; you would see _"Uncaught ReferenceError: $ is not defined"_ – Phil Jan 09 '19 at 01:53
  • `` that doesn't do anything. – Funk Forty Niner Jan 09 '19 at 01:53
  • @FunkFortyNiner I think OP was just saying there's some function calls – Phil Jan 09 '19 at 01:54
  • @Phil Ok. Nice catch (dupe) btw. – Funk Forty Niner Jan 09 '19 at 01:55
  • @FunkFortyNiner I'm aware, it was just a reference to the functions being called in that php file. – Jay Jan 09 '19 at 01:57
  • 1
    @Phil Ahh, yes I see the error in my ways. The fix was adding `type="text/javascript"` in an independent ` – Jay Jan 09 '19 at 02:02
  • [`type` is not required](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type), you just needed a separate ` – Phil Jan 09 '19 at 02:02
  • @Phil I mean, you're correct, but I swear on all that is good in this world, I had my code **exactly** like this and it didn't work. I truly don't know why it's working now... – Jay Jan 09 '19 at 02:04
  • Always have your browser console open when doing front-end work. **Always** – Phil Jan 09 '19 at 02:06
  • @Phil I did I swear! :( There were no console errors, honest lol – Jay Jan 09 '19 at 02:06

0 Answers0