Adaugare nume din PHP in script JavaScript
Scris: Joi Dec 20, 2012
Cum fac la acest chat sa ia automat un nume setat de mine, fara sa il mai scriu eu (vreau sa il conectez la o baza de date).
Cod Script JS:
Cod: Selectaţi tot
<div id="sschat">
<div id="sschat_lines">
<ul></ul>
</div>
<div id="sschat_entry">
<p id="sschat_hint">User Name:</p>
<input type="text" id="sschat_input">
</div>
</div>
Cod: Selectaţi tot
$('#sschat_input').focus();
$('#sschat_input').keyup(function(e) {
if (e.keyCode == 13) {
if (nickname == '') {
if ($('#sschat_input').val() != '') {
listener();
nickname = $('#sschat_input').val();
nickname = nickname.replace(/[^-a-z0-9]/ig,'');
$('#sschat_input').attr('disabled', 'disabled');
$.post(sschat_serverurl+'sschat.php', {action: 'join', nickname: nickname, channel: sschat_channel}, function(data){
$('#sschat_input').val('');
$('#sschat_input').attr('disabled', '');
$('#sschat_hint').html('Type a line of chat and press enter to speak:');
});
}
} else {
var sendline = $('#sschat_input').val();
if (sendline != '') {
$('#sschat_input').attr('disabled', 'disabled');
$('#sschat_input').val('sending...');
serverSend('<span class="nick">'+nickname+':</span> '+sendline);
}
}
}
});