morrisjohnny Posted February 11, 2009 Share Posted February 11, 2009 I've just started using AJAX, now i know how to send and retrive data based on data inputted by an input.Before using Ajax (just html & PHP) i was using a php page to "hold a value"For Example if(isset($_GET['zzz'])){ $cmda=explode(":", $_GET['zzz']); $xxx=$cmda[0]; if($xxx=="user") { //See if user $cmda[1] exists then show the data feild }} Now after the user completes that the value is "held" as $_GET and then the user has another input area where they input some more data however i still need to contain the $_GET['zz']; However i want to use the same input box and just refresh the AJAX part so it shows any already data which has been displayed.If it makes it easier to understand kind of like having a textarea where after submitting text from a input box the textarea keeps a record Link to comment Share on other sites More sharing options...
justsomeguy Posted February 11, 2009 Share Posted February 11, 2009 The textarea should be keeping the data in it, unless you're specifically removing it. This is AJAX, so it's not going to refresh the page and lose the data, the textarea should not be doing anything that the Javascript code isn't specifically telling it to do. Am I misunderstanding something? Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 11, 2009 Author Share Posted February 11, 2009 <?php$gcmd=explode(":",$_GET['q']);if($connected==1){ echo'Connected To'.$connectedto; echo'Just Entered'.$_GET["q"];}else if($gcmd[0]=="connect"){ if($gcmd[] $host=$gcmd[1]; $connected=1; $connectedto=$gcmd[1];}else{ echo'Unknown Command';}?> so as you can see i want to store a variable called connectedto then re-load the same page after another data has been subbmitted, Normally i would just store the value in $_GET format and use $_POST to reload the page, However i'm unsure how this will be done in AJAX? will it just be the same? and how would i go about changing the inport box on the page where the data is entered to POST without a reload? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 11, 2009 Share Posted February 11, 2009 Are you just trying to use a session? You can store whatever you want in the session and it will be available on all PHP pages during the session. Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 11, 2009 Author Share Posted February 11, 2009 a sessions is already started.The data is only required for that page. But a sessions would work if you can start another session after a session has already been set?I've just though of something which might be of a better exampleKind of when you open a forumscategoryid=1then the php looks through the database to retrieve the relevant data. I'm trying to this with AJAX to create a smooth platform.only you type in forums, in <input type="command" /> then a list of categories comes up. Then type in (the same box) the category you wish to view (i don't want to use hyper links it has to be text inputted)So in this example it would store the forums page you first types and then the category your viewing. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 11, 2009 Share Posted February 11, 2009 Well, you keep saying "store" or "hold" or stuff like that, which immediately makes me think of a session. A session will work if you want PHP to keep access to that data without Javascript having to send it back every time (or, you can just send it back every time). If you want Javascript to keep access to that data without having to go to PHP, for that you can just use a local Javascript variable, like a generic object that can hold whatever properties you want to give it. Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 12, 2009 Author Share Posted February 12, 2009 Here's my code trying to create a session how come it's not working. It's apart of another session which might be why it isn't working am i right? Shall i post my whole 5 pages up? <?php$gcmd=explode(":",$_GET['q']);if(isset($_SESSION['connectedto'])){ $display='Connected To'.$_SESSION['connectedto']; $display=$display.'Just Entered'.$_GET["q"];}else if($gcmd[0]=="connect"){ $connectedto=$gcmd[1]; session_start(); $_SESSION['connectedto']==$gcmd[1]; $display=$_SESSION['connectedto'];}else{ $display='Unknown Command';}echo'|'.$display.'|';?> Link to comment Share on other sites More sharing options...
jeffman Posted February 12, 2009 Share Posted February 12, 2009 Do you have a session_start() statement before this:if(isset($_SESSION['connectedto']))?You need one (just one) before any statement that writes OR reads session data. Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 12, 2009 Author Share Posted February 12, 2009 Their wasn't one but i've just added it and it still shows nothing. (i've refreshed the page and cache)Part 1. Problem Solved. $_SESSION['connectedto']=$gcmd[1]; It was Reading $_SESSION['connectedto']==$gcmd[1]; Silly me. It achieves what i want but in a different way but it works, Cheers EveryoneThe other question is how would i store all past information since it can't be good to store 20lines in a session can it?the user inputs data like connect:google (page reloads then session is now set. then if they want another action such as delete google. (pre-defined action) how do i include the past input of connect:google. (it might not be connect but something which isn't pre-defined due to a spelling mistake? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 12, 2009 Share Posted February 12, 2009 You can store whatever you want. It sounds like you should use an array that would act like a stack or buffer. You would push each command onto the end of it, and it would be a chronologic list of commands that were issues (like a stack).e.g. if (!isset($_SESSION['stack'])) $_SESSION['stack'] = array();$_SESSION['stack'][] = $gcmd[1];print_r($_SESSION['stack']); Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 12, 2009 Author Share Posted February 12, 2009 Thanks JustSomeGuy. One Final question how much information can a session old? as i've found this code is better suit $_SESSION['cmdhis']='Usr>'.$_GET['q'].''.$_SESSION['cmdhis']; so it just writes everything i want into the $_SESSION. but worried about a limit if one exists? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 12, 2009 Share Posted February 12, 2009 By default sessions are written to the hard drive, so I would imagine the limit is how much hard drive space is available. Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 12, 2009 Author Share Posted February 12, 2009 Problem Sorted I'll create a log to keep atrack so it doesn't become stupid. :)Sorry to be a pain one final questionHere's my code which starts the AJAX process <input class="windowcommand" type="text" name="exe" onChange="showCode(this.value)" /> Was wondering is their a way to change it so it only searches once enter is press and then the value="" after the value has been sent though. Link to comment Share on other sites More sharing options...
jeffman Posted February 12, 2009 Share Posted February 12, 2009 This is the easiest thing, though I really hate having a lot of code inside page tags: <input class="windowcommand" type="text" name="exe" onChange="showCode(this.value); this.value='';" /> Link to comment Share on other sites More sharing options...
morrisjohnny Posted February 12, 2009 Author Share Posted February 12, 2009 I knew their was something called this.value=''As i have used it to log-in <input type="text" value="Username" onfocus="if(value='Username'){value=''}" />Just with it being onChange i though it would reset to '' everytime the feild was changed.Anyways, Thats me back "in the zone" now Cheers to both of you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.