Hej,
mam problem z takim kodem:
function show(id,login,photo){
$('#messagebox').html("<input type='hidden' id='userId' value='"+id+"'><input type='text' id='msg' class='sendmessage'><button id='send' type='submit' class='button_sendmessage'><i class='icon-right-dir'></i></button>");
$('#message_to').html("<a href='"+login+"'><img src='../userphotos/"+photo+"'>"+login+"</a>");
$("#allmessagesbox").css("visibility","visible");
}
$(document).ready(function(){
var conn = new WebSocket('ws://localhost:8080');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
var data = JSON.parse(e.data);
var row = data.from+": "+data.msg+"<br/>";
$("#chats").append(row);
};
$('#send').click(function(){
var userId = $("#userId").val();
var msg = $("#msg").val();
var data = {
userId: userId,
msg: msg
};
conn.send(JSON.stringify(data));
})
})
Chodzi o funkcję przy $("#send"). Po naciśnięciu buttona z id=send funkcja nie wykonuje się. Myślałem najpierw o tym, że button jest zagnieżdżony w innym divie z innym id, próbowałem sposobu: $('#messagebox > #send'), ale też nie działa.
Dodaję jeszcze kod html.
<div class="allmessagesbox" id="allmessagesbox">
<div class="messages">
<div class="message_to" id="message_to"></div>
</div>
<div class="messagebox" id="messagebox"></div>
</div>
<div id="chats"></div>
Pozdrawiam