All of a sudden my form stopped working (ajax to python view)

Viewed 12

I dont know what happened, all of a sudden my ajax form stopped working, i was only modifying the vdariables.... Could someone please help! im going crazy over here

{% extends "base.html" %}

{% block app_content %}
<head>
    <title>AJAX Example</title>


    <!-- Latest compiled and minified CSS -->
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

    <!-- Latest compiled and minified CSS -->


</head>
    <table class="table table-hover table-striped">

        <body>
            <br>
            <p class="break_here"><p class="paragrpahs">Request R7 Report</p><p class="break_here">
            <br><br>
            Please enter required information for Rapid7 Report:
            <form style="text-align: center; "  action="/rapid7/submit_report/process" method="post">
              <div class="form-group">
                <label class="sr-only" for="reportName">Report name</label>
                <input class="form-control" id="reportName" name="reportName" placeholder="Name of your report">
                <label class="sr-only" for="districtName">District Name</label>
                <input class="form-control" id="districtName" name="districtName" placeholder="Enter Site, ie. District 1 (EUR)">
                <label class="sr-only" for="rapid7Query">Query</label>
                <input class="form-control" id="rapid7Query" name="rapid7Query" placeholder="SELECT * FROM dim_asset">
                <label class="sr-only" for="rapid7SeverityLevel">Severity</label>
                <input class="form-control" id="rapid7SeverityLevel" name="rapid7SeverityLevel" placeholder="Severity Levl (critical, Medeium, Low)">  
                <label class="sr-only" for="scanType">Scan Type</label>
                <input class="form-control" id="scanType" name="scanType" placeholder="Typee of Scan ie Discovery...">  

            </div>
              <div class="form-group">
              
              <button type="submit" class="btn btn-primary" id="btnSubmit">Submit</button><br><br><br>
            </form>
            <br>
            <div id="successAlert" class="alert alert-success" role="alert" style="display:none;"></div><br><br></div>
            <div id="errorAlert" class="alert alert-danger" role="alert" style="display:none;"></div>
            <div style="text-align: center;">
        
    </table>
    <script>

      $(document).ready(function() {
      document.addEventListener("DOMContentLoaded", function(event) { 
          //you can use jQuery there
      });
      $('form').on('submit', function(event) {
          $.ajax({
              data : {
                  reportName : $('#reportName').val(),
                  districtName : $('#districtName').val(),
                  rapid7Query : $('#rapid7Query').val(),
                  scanType : $('#scanType').val(),
                  rapid7SeverityLevel : $('#rapid7SeverityLevel').val(),
              },
              type : 'POST',
              dataType: "json",
              url : '/rapid7/submit_report/process',
              success: function(data){
      
          },
          timeout:5000
          })
          .done(function(data) {
      
              if (data.error) {
                  $('#errorAlert').text(data.error).show();
                  $('#successAlert').hide();
              }
              else {
                  $('#successAlert').text(data.name).show();
                  $('#errorAlert').hide();
                  setTimeout(function() { $("#successAlert").hide(); }, 5000);
      
              }
          
          });
      
          event.preventDefault();
      
      });
      
      });
      
      </script>
      
{% endblock %}

and my view:...

@bp.route("/rapid7/submit_report", methods=["GET"])
@login_required_with_ip_whitelist
def submit_report():
    log_request()
#   vm = Rapid7()
    return render_template("rapid7/submit_report.html")


@bp.route("/rapid7/submit_report/process", methods=["POST"])
@login_required_with_ip_whitelist
def process():
    log_request()
    getFormData = (request.form)
    reportName = (getFormData['reportName'])
    siteName = (getFormData['districtName'])
    rapid7Query = (getFormData['rapid7Query'])
    scanName = (getFormData['scanName'])
    rapid7SeverityLevel = (getFormData['rapid7SeverityLevel'])
    print("In post request response...")
    response = rapid7.check_action(reportName, scanName, siteName, rapid7SeverityLevel, rapid7Query)

it was all working fine, then as soon as i was changing a variable, it crapped out... Im not sure what else i could add that could be of value other than im stuck, i can submit but nothing happens, no errors

0 Answers
Related