-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(function(global) { | ||
'use strict'; | ||
|
||
var XMLHttpRequest = require('../lib/xmlhttprequest'); | ||
|
||
var obj = { | ||
name: 'XMLHttpRequest...', | ||
handleEvent: function(event) { | ||
var client = event.target; | ||
var response = client.response; | ||
console.log('==== %s ====', this.name); | ||
console.log('%s %s', client.status, client.statusText); | ||
console.log(client.getAllResponseHeaders()); | ||
console.log(response.split('\n').slice(0, 3).join('\n')); | ||
console.log('...'); | ||
} | ||
}; | ||
|
||
function request(uri) { | ||
var client; | ||
if (!uri) { | ||
throw new TypeError('URI is required for the argument.'); | ||
} | ||
client = new XMLHttpRequest(); | ||
client.open('GET', uri); | ||
client.responseType = 'text'; | ||
client.addEventListener('load', obj, false); | ||
client.send(null); | ||
} | ||
|
||
function main(argv) { | ||
try { | ||
request.apply(this, argv.slice(2)); | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
} | ||
|
||
main(process.argv); | ||
})(this); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(function(global) { | ||
'use strict'; | ||
|
||
var XMLHttpRequest = require('../lib/xmlhttprequest'); | ||
|
||
var API_URI = 'http://registry.npmjs.org/w3c-xmlhttprequest'; | ||
|
||
function request(searchKeyword) { | ||
var client = new XMLHttpRequest(); | ||
client.open('GET', API_URI); | ||
client.responseType = 'json'; | ||
client.addEventListener('load', function(event) { | ||
var response = client.response; | ||
var result = JSON.stringify(response, null, ' '); | ||
console.log(result); | ||
}); | ||
client.send(null); | ||
} | ||
|
||
function main(argv) { | ||
request.apply(this, argv.slice(2)); | ||
} | ||
|
||
main(process.argv); | ||
})(this); |