binxalot Posted March 21, 2007 Share Posted March 21, 2007 I'm having a mental block, I'm ok with my php coding but when I run into javascript my mind can't handle it, I don't have enough experience with it to use it effectively, but it allows for loading content without a refresh. So I ran into the jah.js file and how to use it to load pages into a site: Code of the jah.js is this: function jah(url,target) { // native XMLHttpRequest object document.getElementById(target).innerHTML = ''; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = function() {jahDone(target);}; req.open("GET", url, true); req.send(null); // IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = function() {jahDone(target);}; req.open("GET", url, true); req.send(); } } } function jahDone(target) { // only if req is "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { results = req.responseText; document.getElementById(target).innerHTML = results; } else { document.getElementById(target).innerHTML="jah error:\n" + req.statusText; } } } You need to add this to before the head tag <script language="javascript1.3" src="jah.js" ></script> Then this to dictate where content gets loaded <div id="content"></div> Then you use this as the link code for text or image links javascript:jah('contact.php','content'); This all works fine and good, I use it because an mp3 player wont skip if you change content in the page since the page wont refresh itself. The problem I have is this. I can't get static links for the pages anymore. Since the content for each page loads into the <div> tag I end up with only an index.php page and no subpages like you would find on a normal site. What I'm looking to do is add in some javascript or php code that uses a $_GET['page']; for hard links to pages on the site. So if I want to load the contact page I would do index.php?page=contact Then I my code I would do: <? if(isset($_GET['page'])){ $page = $_GET['page']; if($page == "contact"){ print "<script language=\"JavaScript\">"; print "javascript:jah('contact.php','content');"; print "</script>"; } } ?> This doesnt work, I want the javascript:jah('contact.php','content' to run the jah.js file when a person uses this link in their address bar: index.php?page=contact . Can someone tell me what I need do to get this to work? Thanks, -Binx Quote Link to comment Share on other sites More sharing options...
tomfmason Posted March 21, 2007 Share Posted March 21, 2007 We don't really support third party apps here. I suggest that you check out some of the tutorials at http://ajaxfreaks.com and take the time to learn how to do this without third party apps. You will find, after you get the hang of it, that ajax is really pretty simple to work with. Tom Quote Link to comment Share on other sites More sharing options...
binxalot Posted March 22, 2007 Author Share Posted March 22, 2007 Yeah, I guess I'll just make those pages up as normal php pages and dup the content from the database. Quote Link to comment Share on other sites More sharing options...
binxalot Posted March 22, 2007 Author Share Posted March 22, 2007 okay, I looked through the board and found a similar post, it fixed my problem. If anyone else is running into the same problem, I used this as a fix: <? if(isset($_GET['page'])){ $page = $_GET['page']; if($page == "contact"){ print "<script language=\"JavaScript1.3\">"; print "setTimeout(\"jah('contact.php','content');\",10);"; print "</script>"; } } ?> the setTimeout will run the jah command after 10 miliseconds and will load the contact page into the <div> tag. Good stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.