- var usr = 'u' + Math.random();
- $.ajax({
- type: "GET",
- url: "http://www.xx.xx:x/atool/" + usr,
- });
- $(document).ready(function() {
- $('#newmessage').submit(function(e) {
- var message = $("#messageinput").val();
- $.ajax({
- 'type' : 'POST',
- 'url' : 'http://www.xx.xx:x/atool/put/atool/' + usr,
- 'data' : { 'message': message },
- 'dataType' : 'json',
- });
- // show_msg(message);
- $("#messageinput").val('');
- e.preventDefault();
- });
- var longPoll = function() {
- return $.ajax({
- type: "POST",
- url: "http://www.xx.xx:x/atool/poll/" + usr,
- async: true,
- cache: false,
- timeout: 100000,
- success: function(data) {
- console.log(data);
- if (data.length > 0) {
- show_msg(data.split(':')[1]);
- }
- return longPoll();
- },
- dataType: 'json'
- });
- };
- longPoll();
- });
- //该片段来自于http://www.codesnippet.cn/detail/1706201512886.html
来源: http://www.codesnippet.cn/detail/1706201512886.html