P
P
Poul002021-06-16 17:19:36
JavaScript
Poul00, 2021-06-16 17:19:36

How to fix the error?

At first, the program works fine, but at some point, alert () does not appear, and after the next request, I get an error.

Error code:

Exception occurred during processing of request from ('127.0.0.1', 58162)
Traceback (most recent call last):
  File "C:\Users\drygo\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 683, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Users\drygo\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Users\drygo\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 747, in __init__
    self.handle()
  File "C:\Users\drygo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
    self.handle_one_request()
  File "C:\Users\drygo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "C:\Users\drygo\AppData\Local\Programs\Python\Python39\lib\socket.py", line 704, in readinto
    return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] Программа на вашем хост-компьютере разорвала установленное подключение


I think that this is a problem with Django itself (although the response itself is formed normally, without errors), because it happens that alert () is not displayed when the response is received, but everything is fine with the other response. What could be the problem?

python, request handler:
def test(request):
        bombs = int(request.POST['bombs_counts'])
        
  r = generate_map(bombs)

  return HttpResponse(json.dumps(r))


html:
<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
  <div class="form_container">
  <div id="message"></div>
  <form id="form">
    {% csrf_token %}
    <input type="text" name="bet">
    <input type="text" name="bombs_counts">
    <input type="checkbox" name="x2">X2
    <input type="checkbox" name="x3">X3
    <input type="checkbox" name="x4">X4
    <input type="submit" name="send" value="Отправить">
  </form>
</div>
<script>
$("#form").on("submit", function(){
  $.ajax({
    url: 'test/',
    method: 'post',
    dataType: 'html',
    data: $(this).serialize(),
    success: function(data){
      $('#message').html(data);
      alert(data);
    }
  });
});
</script>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question