Page 1 of 1

Send to db then refresh

Posted: Thu Jun 09, 2011 12:59 pm
by ashwood
Basically i want to send information thats in a textbox to the database.. once sent to the database i want to refresh a different div if you get me so user types.. clicks submit.. info goes database then a div refreshes.. but im unsure on how to do it and what the easyest way is.

Thanks Ash

Re: Send to db then refresh

Posted: Thu Jun 09, 2011 2:29 pm
by jacek
When you say refresh a div, I assume you are talking about making an AJAX request for something than then setting that to the innerHTML attribute of the div.

If so, is the content that you are refreshing just going to make what is sent via the textbox appear ? Because you can just add to the div with JavaScript, no need to refresh it at all.

Re: Send to db then refresh

Posted: Thu Jun 09, 2011 2:46 pm
by ashwood
jacek wrote:When you say refresh a div, I assume you are talking about making an AJAX request for something than then setting that to the innerHTML attribute of the div.

If so, is the content that you are refreshing just going to make what is sent via the textbox appear ? Because you can just add to the div with JavaScript, no need to refresh it at all.
no what it is, is.. in the div will contain data from the database.. basically i am trying to make a shoutbox.. infact i have just had a idea..

div refresh every 1 second via jquery..

send to db via jquery i can do both them just not all in one..


i think i just had a lightbulb appear above my head :)

Re: Send to db then refresh

Posted: Thu Jun 09, 2011 3:24 pm
by jacek
Okay but refreshing a div is not the best use of AJAX, it would be better to only transfer the data (i.e. just the messages) and create the layout with JavaScript. also every 1 second is far too often.

Re: Send to db then refresh

Posted: Thu Jun 09, 2011 4:01 pm
by ashwood
jacek wrote:also every 1 second is far too often.
not really because what if someone posts and it doesnt show for like 5 seconds? they could be like wtf and keep posting until they see it... and as i cant refresh as the message is posted aswell as say every 30 seconds ever 1 second is how its going to have to be until i find out a better solution.

Re: Send to db then refresh

Posted: Thu Jun 09, 2011 4:13 pm
by jacek
Which is why I said you should have the message added to the div when they submit the form, not just relying on the auto updating.