Created
June 27, 2010 12:22
-
-
Save azu/454863 to your computer and use it in GitHub Desktop.
NILScriptでXMLHttpRequest的なものを書くテスト
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
// ==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