I am new to jQuery and I cannot figure out why this snippet of code does not work, even though it is similar to many of the ones I've found online.
I have two files, index.php
and masterPage.php
. I want to include a <div>
from masterPage.php
called my_table
into index.php
. The thing is that, even if I cannot see the results, I do not catch any error either. Any ideas? It must be something really basic I am missing here.
Here is my code for index.php
:
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery/jquery-3.3.1.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$( "#something" ).load( "./masterPage.php #my_table", {limit: 25},
function (responseText, textStatus, req) {
if (textStatus == "error") {
return "oh noes!!!!";
}
});
});
</script>
</head>
<body>
<div class="something">
</div>
</body>
</html>
Thanks!
You wrote class name for div and accessing like id element(#something) from jquery. Because of that jquery not producing any error. jQuery is checking for something which was wrote as id in document.
Change
<div class="something">
to <div id="something">
Then it will produce result if the url called otherwise it gives error.