|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>AJAX Wait Examples - Webship Testing</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + font-family: Arial, sans-serif; |
| 10 | + max-width: 1200px; |
| 11 | + margin: 0 auto; |
| 12 | + padding: 20px; |
| 13 | + background: #f5f5f5; |
| 14 | + } |
| 15 | + .example-section { |
| 16 | + background: white; |
| 17 | + padding: 20px; |
| 18 | + margin: 20px 0; |
| 19 | + border-radius: 8px; |
| 20 | + box-shadow: 0 2px 4px rgba(0,0,0,0.1); |
| 21 | + } |
| 22 | + button { |
| 23 | + background: #007bff; |
| 24 | + color: white; |
| 25 | + border: none; |
| 26 | + padding: 10px 20px; |
| 27 | + border-radius: 4px; |
| 28 | + cursor: pointer; |
| 29 | + margin: 5px; |
| 30 | + } |
| 31 | + button:hover { |
| 32 | + background: #0056b3; |
| 33 | + } |
| 34 | + input { |
| 35 | + padding: 8px; |
| 36 | + margin: 5px; |
| 37 | + border: 1px solid #ddd; |
| 38 | + border-radius: 4px; |
| 39 | + width: 300px; |
| 40 | + } |
| 41 | + table { |
| 42 | + width: 100%; |
| 43 | + border-collapse: collapse; |
| 44 | + margin: 10px 0; |
| 45 | + } |
| 46 | + th, td { |
| 47 | + border: 1px solid #ddd; |
| 48 | + padding: 10px; |
| 49 | + text-align: left; |
| 50 | + } |
| 51 | + th { |
| 52 | + background: #f8f9fa; |
| 53 | + } |
| 54 | + .success-message { |
| 55 | + color: green; |
| 56 | + padding: 10px; |
| 57 | + margin: 10px 0; |
| 58 | + background: #d4edda; |
| 59 | + border-radius: 4px; |
| 60 | + } |
| 61 | + </style> |
| 62 | +</head> |
| 63 | +<body> |
| 64 | + <h1>AJAX Wait Testing Examples</h1> |
| 65 | + <p>This page demonstrates scenarios that require waiting for AJAX requests to complete.</p> |
| 66 | + |
| 67 | + <!-- Example 1: AJAX Search --> |
| 68 | + <div class="example-section"> |
| 69 | + <h2>Example 1: AJAX Search</h2> |
| 70 | + <input type="text" id="search-input" placeholder="Enter search term"> |
| 71 | + <button onclick="performSearch()">Search</button> |
| 72 | + <div id="search-results-container"></div> |
| 73 | + </div> |
| 74 | + |
| 75 | + <!-- Example 2: AJAX Form Submission --> |
| 76 | + <div class="example-section"> |
| 77 | + <h2>Example 2: AJAX Form Submission</h2> |
| 78 | + <input type="text" id="name-input" placeholder="Your Name"><br> |
| 79 | + <input type="email" id="email-input" placeholder="Your Email"><br> |
| 80 | + <button onclick="submitForm()">Submit</button> |
| 81 | + <div id="form-results-container"></div> |
| 82 | + </div> |
| 83 | + |
| 84 | + <script> |
| 85 | + // Example 1: AJAX Search with XMLHttpRequest |
| 86 | + function performSearch() { |
| 87 | + const query = document.getElementById('search-input').value; |
| 88 | + document.getElementById('search-results-container').innerHTML = '<p>Loading...</p>'; |
| 89 | + |
| 90 | + // Simulate AJAX request |
| 91 | + const xhr = new XMLHttpRequest(); |
| 92 | + xhr.open('GET', 'data:text/plain,success', true); |
| 93 | + |
| 94 | + xhr.onload = function() { |
| 95 | + setTimeout(() => { |
| 96 | + document.getElementById('search-results-container').innerHTML = ` |
| 97 | + <h3>Search Results</h3> |
| 98 | + <table> |
| 99 | + <tr> |
| 100 | + <th>Product</th> |
| 101 | + <th>Actions</th> |
| 102 | + </tr> |
| 103 | + <tr> |
| 104 | + <td>Laptop Pro 15</td> |
| 105 | + <td><button onclick="viewDetails('Laptop Pro 15')">View Details</button></td> |
| 106 | + </tr> |
| 107 | + </table> |
| 108 | + `; |
| 109 | + }, 500); |
| 110 | + }; |
| 111 | + |
| 112 | + xhr.send(); |
| 113 | + } |
| 114 | + |
| 115 | + function viewDetails(product) { |
| 116 | + document.getElementById('search-results-container').innerHTML = ` |
| 117 | + <h3>Product Details</h3> |
| 118 | + <p>Showing details for ${product}</p> |
| 119 | + `; |
| 120 | + } |
| 121 | + |
| 122 | + // Example 2: AJAX Form Submission with XMLHttpRequest |
| 123 | + function submitForm() { |
| 124 | + const name = document.getElementById('name-input').value; |
| 125 | + const email = document.getElementById('email-input').value; |
| 126 | + document.getElementById('form-results-container').innerHTML = '<p>Submitting...</p>'; |
| 127 | + |
| 128 | + // Simulate AJAX request |
| 129 | + const xhr = new XMLHttpRequest(); |
| 130 | + xhr.open('POST', 'data:text/plain,success', true); |
| 131 | + |
| 132 | + xhr.onload = function() { |
| 133 | + setTimeout(() => { |
| 134 | + document.getElementById('form-results-container').innerHTML = ` |
| 135 | + <div class="success-message"> |
| 136 | + <p>Form submitted successfully</p> |
| 137 | + <p>Thank you, ${name}</p> |
| 138 | + </div> |
| 139 | + `; |
| 140 | + }, 800); |
| 141 | + }; |
| 142 | + |
| 143 | + xhr.send(); |
| 144 | + } |
| 145 | + </script> |
| 146 | +</body> |
| 147 | +</html> |
0 commit comments