-
Notifications
You must be signed in to change notification settings - Fork 1
Ex8 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ex8 #14
Changes from all commits
85316b4
01776e1
6d0dd6b
1124865
5c3b467
dcca942
05a6233
b455386
51cd785
97ebba7
e971f83
8edf9b7
81f4de6
b091a64
1fc7af5
529657f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| node_modules | ||
| *.*~ | ||
| .*.swp |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| function ajax_get(url, callback) { | ||
| xmlhttp = new XMLHttpRequest(); | ||
| xmlhttp.onreadystatechange = function() { | ||
| if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen is |
||
| console.log('responseText:' + xmlhttp.responseText); | ||
| try { | ||
| var data = JSON.parse(xmlhttp.responseText); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: while this is fine in javascript, it's customary (and mandatory in other languages) to move the |
||
| } catch(err) { | ||
| console.log(err.message + " in " + xmlhttp.responseText); | ||
| return; | ||
| } | ||
| callback(data); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you fine with the callback being called with undefined (if the responseText cannot be JSON-parsed? Maybe throw an error instead (or signal something else to the callback (two standard options: 1) have two callbacks - one for success - with data, one for failure - with some error message) 2) have a first param to the callback be error - if it's null, the next param is the parsed json) |
||
| } | ||
| }; | ||
|
|
||
| xmlhttp.open("GET", url, true); | ||
| xmlhttp.send(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| requirejs.config({ | ||
| baseUrl: 'js', | ||
| paths: { | ||
| ajax: 'ajax', | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use requirejs' |
||
| update: 'updatePhoneBook' | ||
| } | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing
varstatement.