Created
February 20, 2017 16:46
-
-
Save anonymous/e743b17f53a4788a46e079c36483bad7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
//$('body').css("background-color" , "red"); | |
//wysłanie textu | |
$('#send').click(function() { | |
var wartosc_text= $('#textSend').val(); | |
$.ajax({ | |
type:"POST", | |
url:"czatSend.php", | |
data: {klucz_ajax: wartosc_text}, | |
success:function() { | |
alert("Wysłano do bazy danych"); | |
}, | |
error: function(blad) { | |
alert( "Wystąpił błąd"); | |
console.log(blad); /*Funkcja wyświetlająca informacje | |
o ewentualnym błędzie w konsoli przeglądarki*/ | |
} | |
}); | |
}); | |
setTimeout( function(){ | |
$.ajax({ | |
type:"GET", /*Informacja o tym, że dane będą pobierane*/ | |
url:"czatRead.php", /*Informacja, o tym jaki plik będzie przy tym wykorzystywany*/ | |
contentType:"application/json; charset=utf-8", /*Informacja o formacie transferu danych*/ | |
dataType:'json', | |
success: function(json) { | |
for (var klucz in json){ | |
var wiersz = json[klucz]; /*Kolejne przebiegi pętli wstawiają nowy klucz*/ | |
var id = wiersz[0]; | |
var id_player = wiersz[1]; | |
var text = wiersz[2]; | |
/*Ustalenie sposobu wyświetlania pobranych danych w bloku div*/ | |
$("<span>id: "+id_player+" text: "+text+"</span>") | |
.appendTo('#pojemnik') | |
.append("<hr>"); | |
} | |
}, | |
error: function(blad) { | |
alert( "Wystąpił błąd kurwa nie gadaj"); | |
console.log(blad); /*Funkcja wyświetlająca informacje | |
o ewentualnym błędzie w konsoli przeglądarki*/ | |
} | |
}); | |
} , 1000 ); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment