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
<script src="/socket.io/socket.io.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | |
<script type="text/javascript"> | |
var my_username = ''; | |
function send_individual_msg(id) | |
{ | |
//alert(id); | |
//alert(my_username); | |
socket.emit('check_user', my_username, id); | |
//socket.emit('msg_user', id, my_username, prompt("Type your message:")); |
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
var app = require('express').createServer() | |
var io = require('socket.io').listen(app); | |
var fs = require('fs'); | |
app.listen(8008); | |
// routing | |
app.get('/', function (req, res) { | |
res.sendfile(__dirname + '/chat.html'); | |
}); |
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
function loadJson(callback) { | |
var XmlHttpRequest = new XMLHttpRequest(); | |
XmlHttpRequest.overrideMimeType("application/json"); | |
XmlHttpRequest.open('GET', 'file.json', true); | |
XmlHttpRequest.onreadystatechange = function () { | |
if (XmlHttpRequest.readyState == 4 && XmlHttpRequest.status == "200") { | |
// .open will NOT return a value | |
// but simply returns undefined in async mode so use a callback | |
callback(XmlHttpRequest.responseText); | |
} |
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
<?php | |
//error_reporting(E_ALL); | |
//var_dump($_SERVER); | |
$post_data = $_POST['data']; | |
if (!empty($post_data)) { | |
$dir = 'YOUR-SERVER-DIRECTORY/files'; | |
$file = uniqid().getmypid(); | |
$filename = $dir.$file.'.txt'; | |
$handle = fopen($filename, "w"); | |
fwrite($handle, $post_data); |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Save Data with Ajax and PHP</title> | |
</head> | |
<body> | |
<textarea id="data">Enter some content here you want to save as a file</textarea> | |
<button id="save" onclick="save();return false;">Save</button> | |
<div id="response"></div> |