Send to db then refresh

JavaScript related questions should go here.
Post Reply
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Send to db then refresh

Post 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
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Send to db then refresh

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Send to db then refresh

Post 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 :)
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Send to db then refresh

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: Send to db then refresh

Post 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.
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Send to db then refresh

Post 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.
Image
Post Reply