Kod
function reShout(){
$.getJSON(
"/",
{page:"getShout",nr:$("#last").val()},
function(mesgs){
$.each(mesgs.mesg,function(n,item){
var newMesg=$("<div>");
newMesg.addClass("item");
newMesg.addClass(item.class);
newMesg.html("<strong>"+item.autor+"</strong> <small>"+item.date+"</small><br/>"+item.text);
$("#shoutbox").append(newMesg);
});
$("#last").val(mesgs.lastNr);
$("#shoutbox").attr("scrollTop",$("#shoutbox").attr("scrollHeight")-$("#shoutbox").attr("offsetHeight"));
}
);
setTimeout("reShout();",3000);
}
$(document).ready(function(){
$("form[@name='shoutForm']").submit(function(event){
$.post("/sendMesg",
{mesg:this.mesg.value},
function(){
reShout();
});
this.mesg.value="";
return false;
event.preventDefault();
});
reShout();
});
$.getJSON(
"/",
{page:"getShout",nr:$("#last").val()},
function(mesgs){
$.each(mesgs.mesg,function(n,item){
var newMesg=$("<div>");
newMesg.addClass("item");
newMesg.addClass(item.class);
newMesg.html("<strong>"+item.autor+"</strong> <small>"+item.date+"</small><br/>"+item.text);
$("#shoutbox").append(newMesg);
});
$("#last").val(mesgs.lastNr);
$("#shoutbox").attr("scrollTop",$("#shoutbox").attr("scrollHeight")-$("#shoutbox").attr("offsetHeight"));
}
);
setTimeout("reShout();",3000);
}
$(document).ready(function(){
$("form[@name='shoutForm']").submit(function(event){
$.post("/sendMesg",
{mesg:this.mesg.value},
function(){
reShout();
});
this.mesg.value="";
return false;
event.preventDefault();
});
reShout();
});
A tak html:
Kod
<form name="shoutForm" method="post" action="/sendShout">
<div id="box_komunikator">
<div class="box_tytul">» Komunikator</div>
<div style="height:300px; overflow-y:scroll;" id="shoutbox"></div>
<input type="text" name="mesg" style="width:220px; padding:5px; margin-left:20px; margin-top:20px; border: solid 1px #AB1B15; background:#fff; font: 800 11px tahoma; color:#444; display:block;"/>
<input type="submit" value="Wyślij" style="margin:5px 20px 5px 0; float:right"/>
<input type="hidden" id="last" name="last" defaultValue="0" value="0" />
</div>
</form>
<div id="box_komunikator">
<div class="box_tytul">» Komunikator</div>
<div style="height:300px; overflow-y:scroll;" id="shoutbox"></div>
<input type="text" name="mesg" style="width:220px; padding:5px; margin-left:20px; margin-top:20px; border: solid 1px #AB1B15; background:#fff; font: 800 11px tahoma; color:#444; display:block;"/>
<input type="submit" value="Wyślij" style="margin:5px 20px 5px 0; float:right"/>
<input type="hidden" id="last" name="last" defaultValue="0" value="0" />
</div>
</form>
W tym inpucie #last przechowuje ID ostatnio pobranej wiadomości.
Jak można w IE zapobiec wysyłaniu się formularza? A może jest jakiś lepszy sposób na shoutbox, np. bez formularza? Ale wtedy trzebaby jakoś ustawić enter=wysłanie wiadomości...
Proszę o pomoc w rozwiązaniu tego

Znalazłem rozszerzenie do jQuery - form, ale i z tym IE przekierowuje do action formularza, zamiast tylko wykonać request ajaxem ;/