Jump to content

PHP Theory help


Space_monkey

Recommended Posts

Although this is the PHP coding section i couldn't think of a better place to post this, it has more to do with theory or a way for me to achieve what I want rather than a piece of code which I cant get to work.

 

I have been working on this project, sort of a note taking application. When a new note is added to the database, after the ajax, the page is refreshed and then the new note appears along with the note title in the navigation pane. My problem is when I put the site up on my web server it runs more slowly so when the page is refreshed after the ajax the data is not yet in the database so it needs a second manual refresh for the data to appear. I tried delaying the refresh a tenth of a second and it sort of worked but I ran into problems when actually trying to implement it.

 

But after getting frustrated, I have decided that my refresh workaround isn't very elegant. Is there a technique or method I could use to have certain parts 'refresh' without actually refreshing?

 

I'm sure it is possible and probably quite simple I can think of lots of times when this sort of thing would be needed. Even just making a comment on facebook the whole page isn't refreshed, it just appears. Or rather somehow knows there is new data in the database and updates its self. But this is my first real php project so I'm still learning how everything is done.

Link to comment
Share on other sites

Sorry didn't quite understand that. I'm still trying to understand all this.

 

The ajax that I use is actually jQuery and looks like this

	var level1content = $('#level1content').html();
	var level1title = $('#level1title').html();
	var noteid = <?php echo $level1id; ?>;


     $.ajax({

                 url: 'savelevel1.php',

                 type: 'POST',

                 data:	{
		level1content: level1content,
		level1title: level1title,
		noteid: noteid,
		}
});

Then in savelevel1.php I insert it into my database. Then after refreshing it shows up when the database is queried again. I know there is a success option I can use to call a function on success but I'm not sure how that would help.

Link to comment
Share on other sites

on savelevel1.php after you insert a new row in the database , echo the result

 

and on the ajax , add the sucess function and inside it add ("#mydiv").after or .before if you want the result to appear after the div you show the notes or before and then add (result) which is the success function(result)

Link to comment
Share on other sites

Sorry still don't quite get it. I probably seem like an idiot because they way your explaining it, it sounds quite simple.

 

I don't understand how echoing $result would help because it only gives info on the result of the query eg. "query empty" and that page isn't ever viewed, its just used by the ajax function which is on member.php Unless I'm thinking of the wrong function.

Link to comment
Share on other sites

for example lets say i have a "how are you today" feature with an inputbox and a button

 

then i have a file that does php stuff to show what i have typed in a div(i use some html code to show the message , time , name and stuff, right?) and include it in my div which shows my top10 stories.

 

when i click the button i use ajax to insert it into the database.

inside the ajax file that i call after the insert Query i would copy the html code i use for the structure of the post and insert it after the query in order to show the one i posted after or before the div via this code:

 

after

 success: function(data){
     //show my new post after the div or before?
    $("#mydiv").before(data); //shows what i just typed on the top of the div
    $("#mydiv").after(data); //shows what i just typed on the bottom of the div
}

 

thats how i do it for such a feature..

 

maybe there is someone better at this than me which can explain it better.

 

Good luck ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.