Skip to content

Instantly share code, notes, and snippets.

@azu
Created June 27, 2010 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/454863 to your computer and use it in GitHub Desktop.
Save azu/454863 to your computer and use it in GitHub Desktop.
NILScriptでXMLHttpRequest的なものを書くテスト
// ==UserScript==
// @name XHR
// @namespace http://efcl.info/
// @description XMLHttpRequest的なものを書くテスト
// @author azu
// @homepage http://efcl.info/
// @twitter https://twitter.com/azu_re
// ==/UserScript==
var u=require("HTTP");// ユニット読み込み
var http=new u.HTTP();// クラスのインスタンスを作成
// 非同期じゃない
// HTTP.txt - http.getTextで書いてあるけどリクエストオブジェクトを指定できる。
var xhr1 = http.get({
method :"get",
url : "http://twistar.cc/",
events : {
connect: function(){
println("繫がる");// コマンドプロンプトだと繫とか?になる文字があるので覚えておく
},
response:function(res){
// res.responseText とかできるのかと思ったけど違った。
var res = this.response.readText();
println(res);
},
}
});
// println(xhr1); // 返り値はresponseをreadText()したもの
// リクエストオブジェクトを作ってsend。
var xhr2 = http.request({
method :"get",
url : "http://twistar.cc/",
events : {
connect: function(){
println("接続");
},
response:function(res){
println(this.response.readText());
},
}
})
xhr2.send();
// 必ず配列として返ってくるらしい
var xhrs = http.createRequests({
method :"get",
url : "http://twistar.cc/",
events : {
connect: function(){
println("接続");
},
response:function(res){
println(this.response.readText());
},
}
})
xhrs[0].send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment