ajax1.html 1/2 ajax1.html 2/2 - CS50 CDN

2 downloads 344 Views 66KB Size Report
3: ajax1.html. 4: 5: Gets stock quote from quote1.php via Ajax, displaying result with alert(). 6: 7: Computer Science 5
ajax1.html

1/2

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

78: ajax1 79: 80: 81: 82: Symbol: 83:

84: 85: 86: 87:

2/2

ajax2.html

1/2

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

78: ajax2 79: 80: 81: 82: Symbol: 83:
84: Price: to be determined 85:

86: 87: 88: 89:

2/2

ajax3.html

1/3

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

ajax3 Symbol:

ajax3.html

3/3

lectures/9/src/ajax/ 91:

92: 93: 94:

95: 96: 97:

98: 99: 100: 101:

ajax4.html

1/2

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

69: ajax4 70: 71: 72: 73: Symbol: 74:

75: 76: 77: 78:

ajax5.html

1/3

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

ajax5

ajax5.html lectures/9/src/ajax/ 91: Symbol: 92:

93: Price: 94:
95: High: 96:
97: Low: 98:
99:

100: 101: 102: 103:

3/3

quote1.php

1/1

lectures/9/src/ajax/ 1:

/** * quote1.php * * Outputs price of given symbol as text/html. * * Computer Science 50 * David J. Malan */ // get quote $handle = @fopen("http://download.finance.yahoo.com/d/quotes.csv?s={$_GET["symbol"]}&f=e1l1", "r"); if ($handle !== FALSE) { $ method="get"> Email:
Password:
Password (again):
I agree to the terms and conditions:



form2.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:



form2.html

2/2

lectures/9/src/forms/ 46: form2 47: 48: 49: 50: Email: 51:
52: Password: 53:
54: Password (again): 55:
56: I agree to the terms and conditions: 57:

58: 59: 60: 61:

form3.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:



form3.html

2/2

lectures/9/src/forms/ 46: form3 47: 48: 49: 50: Email: 51:
52: Password: 53:
54: Password (again): 55:
56: I agree to the terms and conditions: 57:

58: 59: 60: 61:

form4.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

54: form4 55: 56: 57: 58: Email: 59:
60: Password: 61:
62: Password (again): 63:
64: I agree to the terms and conditions: 65:

66: 67: 68: 69:

form5.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:



form5.html

2/2

lectures/9/src/forms/ 46: form5 47: 48: 49: 50: Email: 51:
52: Password: 53:
54: Password (again): 55:
56: I agree to the terms and conditions: 57:

58: 59: 60: 61:

dictionary.php

1/2

lectures/9/src/mispellings/ 1:

global $dictionary, $size; if (!file_exists($dict) && is_readable($dict)) return FALSE; foreach (file($dict) as $word) { $dictionary[chop($word)] = TRUE; $size++; } return TRUE; } /* * int * size() * * Returns number of words in dictionary if loaded else 0 if not yet loaded. */ function size() { global $size; return $size; } /* * int * unload() * * Unloads dictionary from memory. */

Returns TRUE if successful else FALSE.

function unload() { return TRUE; }

speller lectures/9/src/mispellings/ 1: #!/usr/bin/php 2:

$ti_size = $after - $before; // unload dictionary $before = microtime(TRUE); $unloaded = unload(); $after = microtime(TRUE); // abort if dictionary not unloaded if (!$unloaded) { print("Could not load $dict.\n"); return 5; } // calculate time to determine dictionary’s size $ti_unload = $after - $before; // report benchmarks printf("\nWORDS MISSPELLED: printf("WORDS IN DICTIONARY: printf("WORDS IN FILE: printf("TIME IN load: printf("TIME IN check: printf("TIME IN size: printf("TIME IN unload: printf("TOTAL TIME:

%d\n", $misspellings); %d\n", $n); %d\n", $words); %.2f\n", $ti_load); %.2f\n", $ti_check); %.2f\n", $ti_size); %.2f\n", $ti_unload); %.2f\n\n", $ti_load + $ti_check + $ti_size + $ti_unload);