Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from cosminpopescu14/issue/put-wrapper-xhr-fun…
…ction-into-their-own-js-file @all-contributors please add @cosminpopescu14 for Code Moved XHR GET in another file.
- Loading branch information
Showing
2 changed files
with
24 additions
and
20 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
22 changes: 22 additions & 0 deletions
22
src/NetCore2Blockly/TestBlocklyHtml/wwwroot/blockly/BlocklyXHRWrapper.js
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,22 @@ | ||
// XHR wrapper functions | ||
|
||
const doGet = (href, callback) => { | ||
|
||
console.log(href, callback); | ||
let req = new XMLHttpRequest(); | ||
req.open('GET', href, true); | ||
req.onreadystatechange = function () { | ||
if (req.readyState == 4) { | ||
if (req.status >= 200 && req.status < 300) { | ||
return callback(req.responseText); | ||
} else { | ||
throw `${href} status :${req.status}`; | ||
} | ||
|
||
} | ||
else { | ||
//window.alert(`error ${href} ${req.status}`); | ||
} | ||
}; | ||
req.send(null); | ||
} |