abbreviation of the form on the server



  • Good day! I'm new, with js On you, with ajax I first met face to face.

    The challenge for me is that chatbot in the ass communicates with the customer of the site, the sabmit of the form (transfer from the user) is transferred to the server each time (communication goes to the tip). When I test local, everything was okay. But downloading to the server has been a problem: after the sabmy of the form, a page of error opens.

    I have the following code:

    $( document ).ready(function() {
    
    function AjaxFormRequest(formData, url) {
    
        jQuery.ajax({
            url: url,
            type: "POST",
            dataType: "html",
            data: JSON.stringify(someJSON),
    

    // success: function(response) {

    // smth

    // },
    error: function(response) {
    console.log('wtf');
    }
    });
    }

    $("#chatbot-submit").click(
        function(){
            AjaxFormRequest();
    

    // return false;

        }
    
    );
    

    });

    Bye.
    // return false;Commented on, throws 404 if you've got a comment, the shape won't sabotage. I need the data to be sent to the sabmit, but the page is not overloaded.

    marking ofation form

    <form action="/algo/bookChat.php" method="post" id="chatform">
    <div class="input-group">
    <input id="chatbot-input" type="text" name="msg" class="form-control" placeholder="Введите сообщение и нажмите Enter..." autocomplete="off" required>
    <div class="input-group-btn">
    <input id="chatbot-submit" class="btn btn-default" type="submit" value="">
    </div>
    </div>



  • Just so you don't go on the other page. https://api.jquery.com/event.preventdefault/

     $("#chatbot-submit").click(
          function( $event ){
    
          AjaxFormRequest(/*тут нехватает данных и урла*/);
          $event.preventDefault();
          return false; //тоже можно, данные не отсылаются не из-за этого
      }
    

    );

    The shape doesn't leave. return falseBecause you don't transfer anything to AjaxFormRequest.

    function AjaxFormRequest(formData, url) { //требуется 2 параметра
    // судя по названию это данные и куда передавать

    jQuery.ajax({
    url: url, //неопределена, в клике вы вызываете ajaxFormRequest без параметров
    type: "POST",
    dataType: "html",
    data: JSON.stringify(someJSON), // someJSON неопределена (всегда)

      error: function(response) {
          console.log('wtf');
      }
    

    });
    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2