form-request / index.html
ShayanRl's picture
Update index.html
2cd773c verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Job Search API</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
padding: 40px;
max-width: 600px;
width: 100%;
}
h1 {
color: #333;
margin-bottom: 30px;
font-size: 28px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
color: #555;
font-weight: 500;
}
input {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 6px;
font-size: 16px;
transition: border-color 0.3s;
}
input:focus {
outline: none;
border-color: #667eea;
}
button {
width: 100%;
padding: 14px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
button:active {
transform: translateY(0);
}
button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
#result {
margin-top: 30px;
padding: 20px;
background: #f5f5f5;
border-radius: 6px;
display: none;
max-height: 400px;
overflow-y: auto;
}
#result.show {
display: block;
}
.error {
color: #d32f2f;
}
.success {
color: #2e7d32;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>Job Search API</h1>
<form id="searchForm">
<div class="form-group">
<label for="searchPhrase">Search Phrase</label>
<input type="text" id="searchPhrase" name="searchPhrase" value="Basis Ed Louisiana" required>
</div>
<div class="form-group">
<label for="pageStartIndex">Page Start Index</label>
<input type="number" id="pageStartIndex" name="pageStartIndex" value="11" min="0" required>
</div>
<div class="form-group">
<label for="pageEndIndex">Page End Index</label>
<input type="number" id="pageEndIndex" name="pageEndIndex" value="20" min="0" required>
</div>
<button type="submit" id="submitBtn">Search Jobs</button>
</form>
<div id="result"></div>
</div>
<script>
const form = document.getElementById('searchForm');
const resultDiv = document.getElementById('result');
const submitBtn = document.getElementById('submitBtn');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const searchPhrase = document.getElementById('searchPhrase').value;
const pageStartIndex = parseInt(document.getElementById('pageStartIndex').value);
const pageEndIndex = parseInt(document.getElementById('pageEndIndex').value);
const requestBody = {
searchPhrase: searchPhrase,
filters: [
{ name: "positionAreas", filters: [] },
{ name: "gradeLevels", filters: [] },
{ name: "jobTypes", filters: [] }
],
pageStartIndex: pageStartIndex,
pageEndIndex: pageEndIndex
};
submitBtn.disabled = true;
submitBtn.textContent = 'Searching...';
resultDiv.classList.add('show');
resultDiv.innerHTML = '<p>Loading...</p>';
try {
// Using free CORS proxy to bypass CORS restrictions
const proxyUrl = 'https://api.allorigins.win/raw?url=';
const apiUrl = 'https://api.k12jobspot.com/api/Jobs/Search';
const response = await fetch(proxyUrl + encodeURIComponent(apiUrl), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'Mozilla/5.0',
'Origin': 'https://k12jobspot.com',
'Referer': 'https://k12jobspot.com/'
},
body: JSON.stringify(requestBody)
});
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = `
<h3 class="success">Success!</h3>
<p><strong>Status:</strong> ${response.status}</p>
<p><strong>Response:</strong></p>
<pre>${JSON.stringify(data, null, 2)}</pre>
`;
} else {
resultDiv.innerHTML = `
<h3 class="error">Error</h3>
<p><strong>Status:</strong> ${response.status}</p>
<pre>${JSON.stringify(data, null, 2)}</pre>
`;
}
} catch (error) {
resultDiv.innerHTML = `
<h3 class="error">CORS Error - Request Blocked</h3>
<p>The API doesn't allow direct browser requests. Here's the request info you need:</p>
<h4>Request Details:</h4>
<p><strong>URL:</strong> https://api.k12jobspot.com/api/Jobs/Search</p>
<p><strong>Method:</strong> POST</p>
<p><strong>Headers:</strong></p>
<pre>Content-Type: application/json</pre>
<p><strong>Body:</strong></p>
<pre>${JSON.stringify(requestBody, null, 2)}</pre>
<h4>Solutions:</h4>
<p>1. Use a backend server (Node.js, Python, etc.) to make the request</p>
<p>2. Use a CORS proxy service</p>
<p>3. Use tools like Postman or curl to test the API</p>
<p>4. Copy the curl command below:</p>
<pre>curl -X POST https://api.k12jobspot.com/api/Jobs/Search \\
-H "Content-Type: application/json" \\
-d '${JSON.stringify(requestBody)}'</pre>
`;
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Search Jobs';
}
});
</script>
</body>
</html>