MrBillybob Posted August 12, 2007 Share Posted August 12, 2007 from my index i want to runpage1.php without leaving index.php how do i do that?...without ajax Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/ Share on other sites More sharing options...
Danltn Posted August 12, 2007 Share Posted August 12, 2007 include 'otherpage.php'; include_once 'otherpage.php'; require 'otherpage.php'; require_once 'otherpage.php'; Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321507 Share on other sites More sharing options...
MrBillybob Posted August 12, 2007 Author Share Posted August 12, 2007 ...don't see how that will work those functions basically inserts the page into the page with that code. i want to run it like a cron almost ps sorry if thats rude but its late Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321509 Share on other sites More sharing options...
balistic Posted August 12, 2007 Share Posted August 12, 2007 use iframes http://en.wikipedia.org/wiki/IFrame Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321514 Share on other sites More sharing options...
ILYAS415 Posted August 12, 2007 Share Posted August 12, 2007 hehe lol iframes arent really gd. Dude ull hav to use on of the codes that Dan specified. Those will actually run the codes on ur page. Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321518 Share on other sites More sharing options...
MrBillybob Posted August 12, 2007 Author Share Posted August 12, 2007 i dont want the script to run on my index because it take a long time... Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321525 Share on other sites More sharing options...
Guest Posted August 12, 2007 Share Posted August 12, 2007 i dont want the script to run on my index because it take a long time... That is unavoidable. If you really want to invoke an external script into the index, it's ultimately going to be processed as if it were on the index page anyway. Now it just depends whether you want it to happen -after-the rest of the page has loaded or -during- the page load. If you want it during, you will use Dan's methods (Require/include/etc.), if you want it after, use AJAX to call in that PHP script. Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321531 Share on other sites More sharing options...
MrBillybob Posted August 12, 2007 Author Share Posted August 12, 2007 ok well how do i use ajax to call it after? Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321534 Share on other sites More sharing options...
Guest Posted August 12, 2007 Share Posted August 12, 2007 Ok, I'm going to write this response assuming you understand basic javascript and how it interacts with HTML pages. first of all, you need to import (or put it into the page directly) this javascript: var xmlhttp = false; function ajax_init() { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(ie) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(other) { xmlhttp = false; } } if( !xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); } } function ajax_request(method, url, nodeID) { var node = document.getElementById(nodeID); xmlhttp.open(method, url, true); xmlhttp.onreadystatechange = function() { if( xmlhttp.readyState == 4 ) { switch( xmlhttp.status ) { case 200: node.innerHTML = xmlhttp.responseText; break; default: node.innerHTML = "There was a server error (" + xmlhttp.status + "), and it could not finish loading. Please try again."; } } } xmlhttp.send('ajax=1'); } Now, ask yourself, does your external script print anything to the screen? Do you want that shown or not? If it doesn't matter, then make an empty <div id="myDiv"></div> at the bottom of the page. (the id can be whatever you like, but I'm going to use myDiv in my examples) If it IS important that the output is shown on the page, replace "myDiv" with the ID of the HTML element where you want it shown. *** Now, on the <body> tag, change it to: <body onload="ajax_init(); ajax_request("post", "externalScript.php", "myDiv");"> Of course, change "externalScript.php" to be your script file. And there you go! It will call that script once the page has loaded. Hopefully that'll work, it's 7am and I wrote that from memory. Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321541 Share on other sites More sharing options...
MrBillybob Posted August 12, 2007 Author Share Posted August 12, 2007 ill test it and thank you if i have any questions can i pm you? Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321542 Share on other sites More sharing options...
Guest Posted August 12, 2007 Share Posted August 12, 2007 Certainly! (Oh, I edited my last post, so be sure to take a look at it before you try it out) Link to comment https://forums.phpfreaks.com/topic/64498-how-to-run-a-script-from-another/#findComment-321543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.