server.py
from http.server import HTTPServer, BaseHTTPRequestHandler
class Server(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.path = '/index.html'
try:
file_to_open = open(self.path[1:]).read()
self.send_response(200)
except:
file_to_open = "File not found"
self.send_response(404)
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))
httpd = HTTPServer(('localhost', 80), Server)
httpd.serve_forever()
This python server is pretty simple.
.js
$.post( "t.json", array);
When I am trying to post to .json file I am getting the following error.
POST http://localhost/t.json 501 (Unsupported method ('POST'))
I have already read:
None of them have been solved by using python