Reputation: 169
i have a table in one html file and div in another and both files are on same server, same folder. I'm trying to use jquery load function to do the folowing. So I do :
$('#div').load('game.html #tbl', function(){ alert ("succes on load");});
As you can see I try to target #tbl which is id of table, and I get the alert that is succes, but no tables were loaded. Can tables be loaded this way?
Upvotes: 0
Views: 56
Reputation: 2267
Look in the browser console, you probably have an error there. You've got to make sure you have the proper path, this is a relative path. If your current doesn't work, try messing around. Add ../
before the path and see if that works. I don't know your file structure so this is probably easier for you.
Another problem could be that you don't have the right permissions on that file, 403 Forbidden
. So, go check your web browser's console.
If you have the following file structure and run the code beneath that, everything should work fine.
/project_name
├── index.html
├── game.html
index.html
<div id="div"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>$('#div').load('game.html #tbl', function(){ alert ("succes on load");});</script>
game.html
<div id="tbl"><h1>I origin from another file</h1></div>
EDIT: After messing around a bit I found the solution. You can't run scripts with .load
just by opening a .html file from your hard drive. You need to install WAMP/LAMP/MAMP (a local server) that you can access by entering localhost
in the browser.
Please have a look here: AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https
Upvotes: 1