woodplease Posted September 22, 2010 Share Posted September 22, 2010 l have a script i got of dynamic drive that loads another page inside a div tag. This works. the page that is loading contains code than when run, reloads that php page to insert data into a database. The problem is that it just reloads the entire page and doesnt enter the data into the database. The main page <div id='fcontrol'><table border='1' class ='tstyle'><tr height ='700'><td valign='top' class='ssbg' width='120'><div id='menu'><a href='javascript:ajaxpage("new_section.php", "contentarea");'>Add new section</a><br/><br/><a href='javascript:ajaxpage("new_sub_section.php", "contentarea");'>Add new section to forum</a><br/><br/><a href='index.php'>Back to forum</a><br/><br/></div></td><td class='tcontrol' width='700' valign='top'><center><div id='contentarea'>Control Panel</div></center></td></tr></table></div></div> the page inside the div if (isset($_POST['new_section'])) { if (!$section_title ) {die('You did not complete all of the required fields<br/><a href="./new_section.php">Back</a>');}$query = "INSERT INTO section_main (section_title) VALUES ('$section_title')";$add_section = mysql_query($query) or die ('could not add new section');?><h1>section added</h1><?php}else{?><form name="add_section" method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>"><table><tr><td>Section Name</td><td><input type="text" name="section_title" maxlength="200" /></td></tr><tr><td></td><td><input type="submit" name="new_section" value="Add Section"/></td></tr></table></form><?php}?> the javascript var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)var loadedobjects=""var rootdomain="http://"+window.location.hostnamevar bustcacheparameter=""function ajaxpage(url, containerid){var page_request = falseif (window.XMLHttpRequest) // if Mozilla, Safari etcpage_request = new XMLHttpRequest()else if (window.ActiveXObject){ // if IEtry {page_request = new ActiveXObject("Msxml2.XMLHTTP")} catch (e){try{page_request = new ActiveXObject("Microsoft.XMLHTTP")}catch (e){}}}elsereturn falsepage_request.onreadystatechange=function(){loadpage(page_request, containerid)}if (bustcachevar) //if bust caching of external pagebustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()page_request.open('GET', url+bustcacheparameter, true)page_request.send(null)}function loadpage(page_request, containerid){if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))document.getElementById(containerid).innerHTML=page_request.responseText}function loadobjs(){if (!document.getElementById)returnfor (i=0; i<arguments.length; i++){var file=arguments[i]var fileref=""if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceedingif (file.indexOf(".js")!=-1){ //If object is a js filefileref=document.createElement('script')fileref.setAttribute("type","text/javascript");fileref.setAttribute("src", file);}else if (file.indexOf(".css")!=-1){ //If object is a css filefileref=document.createElement("link")fileref.setAttribute("rel", "stylesheet");fileref.setAttribute("type", "text/css");fileref.setAttribute("href", file);}}if (fileref!=""){document.getElementsByTagName("head").item(0).appendChild(fileref)loadedobjects+=file+" " //Remember this object as being already added to page}}} I've included all the code related to the problem. i know its a lot, but i wanted to give as much info as possible Quote Link to comment https://forums.phpfreaks.com/topic/214126-loading-an-external-php-page/ Share on other sites More sharing options...
gamesmstr Posted September 23, 2010 Share Posted September 23, 2010 I have my suspicions what is happening, but can you tell me what is actually happening visually? Are you getting any of your error messages? Quote Link to comment https://forums.phpfreaks.com/topic/214126-loading-an-external-php-page/#findComment-1114339 Share on other sites More sharing options...
woodplease Posted September 23, 2010 Author Share Posted September 23, 2010 There are no error messages. when an ajax link is clicked, it loads a (php) page into the div tag. This displays. There is a form in the php page that when submitted, reloads the php page, and runs code to insert the form data into a table. the problem is that it is reloadiung the page with the ajax on, therefore the php page is no longer loaded in the div resulting in the code not running Quote Link to comment https://forums.phpfreaks.com/topic/214126-loading-an-external-php-page/#findComment-1114423 Share on other sites More sharing options...
gamesmstr Posted September 24, 2010 Share Posted September 24, 2010 Separate each action under a condition statement and pass the variable condition as a variable through the ajax funtion... For example: if ($action = ''){ show the form } else if ($action = 'display'){show output} Quote Link to comment https://forums.phpfreaks.com/topic/214126-loading-an-external-php-page/#findComment-1114872 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.