ErcFrtz Posted January 27, 2011 Share Posted January 27, 2011 My problem is this. I have javascript that when a link is clicked it displays the link in a layer over the current page. The new layer is included using the php include command. However when the new layer is displayed, the javascripts that are supposed to run in the new layer do not work. Code examples follow: Original page: <head> <script src="scripts/createAjaxObject.js" type="text/javascript" language="javascript"></script> <script src="scripts/radiocheck.js" type="text/javascript" language="javascript"></script> <script src="scripts/popupscript.js" type="text/javascript" language="javascript"></script> </head> <body> <?php include('search.php'); ?> <table id="blocks"> <tr><td> <h1><a onClick="javascript:displaysearch();">Search</a></h1> </td></tr> </table><br /> The search page that's included: <div id="searchpopup"> <div id="closeBox">Close ⊗</div> <div id="wrapper"> <div id="popupcontent"> content... <p> <input name="searchType" type="radio" value="general" id="generalsearch" onClick="changeInfo('general','single');"> <label for="generalsearch">Search for multiple pigs based on general information.</label> </p> </div> </div> </div> The javascripts: function createObject() { var request_type; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer") { request_type = new ActiveXObject("Microsoft.XMLHTTP"); } else { request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); function changeInfo(type1, type2) { document.getElementById(type1 + "Display").style.display = 'block'; document.getElementById(type2 + "Display").style.display = 'none'; } function showInfo(type) { if(document.getElementById(type + "Display").style.display == 'none') {document.getElementById(type + "Display").style.display = 'block';} else {document.getElementById(type + "Display").style.display = 'none';} } function displaysearch() { document.getElementById('searchpopup').style.display = 'block'; document.getElementById('closeBox').onclick = function(){document.getElementyById('searchpopup').style.display = 'none';} } Now when I click the link on the original page is shows the searchpopup just fine. However, my closebox doesn't actually hide the searchpopup and the changeinfo() does not seem to show/hide the information it's supposed to either. Do I have to have the actual php/hmtl in the original file and not included using the php include command? Quote Link to comment https://forums.phpfreaks.com/topic/225865-php-include-file-ajaxjavascript-not-working-together/ Share on other sites More sharing options...
ErcFrtz Posted January 27, 2011 Author Share Posted January 27, 2011 I figured out why it wasn't working and have got it working. Problem solved. Quote Link to comment https://forums.phpfreaks.com/topic/225865-php-include-file-ajaxjavascript-not-working-together/#findComment-1166066 Share on other sites More sharing options...
sidesteal Posted July 20, 2011 Share Posted July 20, 2011 What was your solution? I have the same problem. I have a link that triggers a modal window with a form. the contents of the window are called with a php include and is rendered in HTML but not visible until you click the modal link. When you fill the form in and submit, AJAX posts the data to another php file that processes the post array and should just print a simple result message. I KNOW the AJAX code is ok as i can simply navigate to the include in my browser and perform the action successfully, but when embedded in the rest of my php code it never works! Please post your solution to how you handled this. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225865-php-include-file-ajaxjavascript-not-working-together/#findComment-1245304 Share on other sites More sharing options...
sidesteal Posted July 20, 2011 Share Posted July 20, 2011 I have just solved this. For me, it was the pathing to the processing file for the posted data. Even though the process form was in the same directory, it needed a full root path to the file in the javascript: WAS: mypostrequest.open("POST", "ajax-form-process.php", true) NOW: mypostrequest.open("POST", "/NNCMS/modules/NNCMS/admin-page-manager/ajax-form-process.php", true) Up till posting in here, i had tried dozens of trial and error solutions for this. At 1 point i thought it was file_get_contents() parsing my template messing with the code somehow, until I knocked up some testing scripts that emulated what i already had in my code. Anyways, it was the trial and error that led me to the pathing fix, although i wished i had thought of it sooner than the 18 hours ive been working to solve this Hope this helps any one searching for the same. Quote Link to comment https://forums.phpfreaks.com/topic/225865-php-include-file-ajaxjavascript-not-working-together/#findComment-1245342 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.