Aksiyon eğer isset..php / javascript

2 Cevap php

I am storing a session variable when a comment is inserted.. called user_message.. and i want to, when user_message, have been stored, THEN, show message on index.php index.php is right now:

<div id="message">
<? echo $_SESSION["user_message"]; ?>
</div>

Ama onun saklanan SONRA mesajı görmek için, siteyi (F5) yenilemek için ihtiyacınız olacak ..

Ama değişken user_message şey saklandığı var ise, o zaman görüntüler istiyorum ..

Umarım anlarsın.

2 Cevap

Eğer kullanıcı üzerinde sayfayı yenilemek istiyorum, o / o yeni bir yorum gönderdi sonra - Ben senin niyetini anlamak emin değilim?

Eğer öyleyse - bir normal form yazı kullanıyorsanız / almak, sonra istediğiniz hiç sayfasında kullanıcı isteği yönlendirme, ve bir uyarı göstermek, the code @Seb wrote above kullanarak yapabilirsiniz.

Eğer Yorum göndermek için ajax kullanarak eğer, sayfa yenilemek gerekiyor ajax arama oluşturulan javascript fonksiyonu bildiren, ajax çağrısından bir yanıt döndürür, ve sonra seni url hiç ne location.href değişkeni ayarlayabilirsiniz istiyorum.

However - if you want to refresh the page for all users seeing the comments page, once another user has sent a comment, you will need to have a repeated ajax call every few seconds/minutes, that checks if something has changed in the server, and if so use the location.href variable to redirect the user to a different. You can't do this if you're relying only on the session variable saved on the computer of the commenter, as it is only accessible when the original commenter is using your site.

Eğer ileti yorumları biçimi olarak aynı sayfada görüntülenmesini istiyorsanız bazı JavaScript öneririz. JQuery kullanıyorsanız http://jquery.com/ o zaman gibi bir şey yapabilirsiniz.

$('form#CommentFormID').submit(function() {
    var message = $('form#CommentFormID textarea#comment').html();
    $('body').append('<div id="message">' + message + '</div');
});

Bu denemedim, ama para cezası çalışması gerekir.