fredted40x Posted April 15, 2010 Share Posted April 15, 2010 Hi all, Im trying to add AJAX to my mini message board, the basic pages of my message board are -Homepage (index.php) -View message subject page - shows message subjects from every message stored in the database and then include a link to view the full message -Message page- this page shows the full message. So far i have made two links on the left menu bar, one being to show the homepage in the div 'textone', and the other showing the message subjects page with the message sujects and a link next to each subject that people can click on to view the whole message. So far this has worked with both links calling a seperate function that canges the div 'textone' innerHTML. Both AJAX functions calls seperate .php files, one including the homepage text and the other including the SQL code to display message subjects. Im now trying to add a link next to all message subjects that calls a function in script.js, but im trying to call it from one of the php files that ajax has called and its not working as the ajax is only linked to the index.php file, is it possible to call a function in a different php file. Heres a bit of code index.php <a href="#home" onclick="home()">Home</a><br/> <a href="#board" onclick="fetch()">Bulletin Board</a><br/> and i have this <script src="script.js"></script> at the top in the HTML head. The script.js has this code in it that calls the page to show bulleting subjects var fetch = function () { var xhr, target, changeListener; target = document.getElementById("dynamicText1"); xhr = new XMLHttpRequest(); changeListener = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { target.innerHTML = xhr.responseText; } else { target.innerHTML = "<p>Something went wrong.</p>"; } } else { } }; xhr.open("GET", "bulletinindex.php"); xhr.onreadystatechange = changeListener; xhr.send(); }; and the bulletinindex.php has this $sql = mysql_query("#removed sql query#"); while($r = mysql_fetch_array($sql)) { $posted = date("jS M Y h:i",$r[posted]); echo "$r[bulletin]<br/> "; $result = " <a href="#home" onclick="home()">Home</a><br/><hr>"; echo $result; } i included the code <a href="#home" onclick="home()">Home</a>< just so i can try and get it working as i know the home function works correctly so once i get that working i can just call a seperate function to view the message, i thought it just added the text into index.php so it would be like that link was actually in the index.php file but it doesnt work and says there is a error on the line echo $result; . Any one got any ideas how i can get it to update textone in index.php? Thank you! p.s. sorry if this is too confusing Quote Link to comment Share on other sites More sharing options...
fredted40x Posted April 15, 2010 Author Share Posted April 15, 2010 sorry it wont let me modify my last post. Hae just thought of another way of explaining it. Basically i want a php file called from AJAX which is called from index.php to be able to make index.php call a function as if the user had clicked a link on index.php that calls a function Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 You messed up the quotes in this line - $result = " <a href="#home" onclick="home()">Home</a><br/><hr>"; Quote Link to comment Share on other sites More sharing options...
fredted40x Posted April 15, 2010 Author Share Posted April 15, 2010 should this work if quotes are correct? whis quotes are wrong? thanks again. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 I don't know if it should work. Test it out instead of asking about it. 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.