Commit 88ae8435 authored by limingzhe's avatar limingzhe

feat: xhr调试

parent ba5b918c
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
</div> </div>
<input type="file" value="请选择文件" />
<form method="POST" [action]="uploadUrl"></form>
<!-- <div style="position: absolute; top: 0"> <!-- <div style="position: absolute; top: 0">
<label style="font-family: Aileron-Black;"></label> <label style="font-family: Aileron-Black;"></label>
......
...@@ -745,7 +745,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -745,7 +745,7 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
const startTime = new Date().getTime(); const startTime = new Date().getTime();
greadPapersForCheck({type: 'pos', blankWord: 'NN', word: 'apple'}, res => { greadPapersForCheck({type: 'VB', blankWord: 'apple', word: 'apple'}, res => {
// res 需要toJSON // res 需要toJSON
const endTime = new Date().getTime(); const endTime = new Date().getTime();
const durTime = endTime - startTime; const durTime = endTime - startTime;
...@@ -799,15 +799,39 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -799,15 +799,39 @@ export class PlayComponent implements OnInit, OnDestroy {
url2Blob (url) { url2Blob (url) {
return new Promise(resolve => { return new Promise(resolve => {
console.log(' in url2Blob ..')
console.log('url: ', url);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('get', url, true); xhr.open('get', url, true);
xhr.responseType = 'blob'; xhr.responseType = 'arraybuffer';
xhr.onload = () => { // xhr.onload = () => {
if (xhr.status == 200) {
// console.log(' in url2Blob load end..')
// if (xhr.status == 200) {
// console.log(xhr.response); // console.log(xhr.response);
// resolve(xhr.response);
// }
// };
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4) {
return;
}
const status = xhr.status;
console.log ('status: ', status);
if ((status >= 200 && status < 300) || status === 304) {
console.log('request success');
console.log(xhr.response);
resolve(xhr.response); resolve(xhr.response);
} else {
console.log('request error');
console.log('xhr.response: ', xhr.response);
} }
}; };
xhr.send(); xhr.send();
...@@ -817,14 +841,16 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -817,14 +841,16 @@ export class PlayComponent implements OnInit, OnDestroy {
uploadTestAudio(text, url, key) { uploadTestAudio(text, url, key) {
console.log(' in uploadTestAudio 111');
this.url2Blob(url).then((res) => { this.url2Blob(url).then((buffer) => {
console.log('res: ', res); console.log('res: ', buffer);
const startTime = new Date().getTime(); const startTime = new Date().getTime();
const blob = res //new Blob([u8arr], {type: mime}); const blob = new Blob([<ArrayBuffer>buffer], {type: "audio/mpeg"});
// const blob = res //new Blob([u8arr], {type: mime});
const fd = new FormData(); const fd = new FormData();
fd.append("file", <Blob>blob, 'test_audio.mp3'); fd.append("file", <Blob>blob, 'test_audio.mp3');
this.http.post(this.uploadUrl, fd).subscribe((res) => { this.http.post(this.uploadUrl, fd).subscribe((res) => {
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">
<script type="text/javascript" src="https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air_online_open.js"></script> <script type="text/javascript" src="https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air_online_open.js"></script>
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
<script> <script>
// init vConsole // init vConsole
var vConsole = new VConsole(); var vConsole = new VConsole();
console.log('Hello world'); console.log('Hello world');
</script> --> </script>
</head> </head>
<body> <body>
<app-root></app-root> <app-root></app-root>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment