SQLの窓 イラストAC フリー素材

2012年05月31日

Windows8 の XMLHttpRequest の POST メソッドのテストの為に、超簡易掲示板を授業中に作成

toypark は、オンラインで WEBベースの クライアントアプリがあるので、直接タイプして登録。最初、Seesaa のブログの記事のコメント欄を使ってたら、しばらくしてスパム扱いされて書き込み禁止になってしまったので・・・

で、Windows8 が UTF-8 で、他のキャラクタセットの URL エンコードが必要になったので、ecl.js をベクターからダウンロードして、Windows8 に実装しましたが、普通に動きます。ほんと、このライブラリは良くできています。
<?
header( "Content-Type: text/html; Charset=shift_jis" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

error_reporting(E_ALL ^ E_NOTICE);

ini_set( 'display_errors', "1" );

?>
<html>
<form method="POST">
<textarea name="text"></textarea>
<input type="submit" name="send" value="送信">
</form>
<?
$text = @file_get_contents("./text.log");


if ( $_POST['send'] != "" ) {
    $text .= "<br />\n" . $_POST['text'];
    file_put_contents("./text.log", $text );
}


print $text;
?>
</html>
以下のコードは、Windows8サンプルの『Secondary tiles sample』の中にあります。これは、データを決め打ちで処理していますが、ecl.js は正しく動作しています。
( JavaScript のみで、日本語が Shift_JIS に変換されて URL エンコードされます )

★ コンシューマからリリースの変化で、サンプルの中身も変わったようです。
★ XMLHttpRequest のサンプルは、Metro style banking app with strong authentication sample を見て下さい

    function scenario7RefreshChannels() {
        var serverUrl = document.getElementById("serverUrlField").value;

        // Send the channel to the server
        var xhr = new WinJS.xhr({
            type: "POST",
            url: serverUrl,
            headers: { "Content-Type": "application/x-www-form-urlencoded" },

            // Send the tile id of the secondary tile for handling in your service, in addition to the channelUri
            data: "tileId=abc&channelUri=xyz"

        }).then(function (req) {
            id("scenario7Output").innerHTML += req.response;
        }, function (req) {
            sdkSample.displayError("Could not send channel URI to server: " + req.statusText);
        });
    }
関連する記事

JavaScript のみで、SHIFT_JIS や EUC-JP を UrlEncode に近い Escapeする Escape Codec Library


【オワコンの最新記事】
posted by at 2012-05-31 20:42 | オワコン | このブログの読者になる | 更新情報をチェックする