Good day! I'm new to js
on you, with ajax
first met face to face.
The task in front of me is the following: a chatbot in a pop-up communicates with a site visitor, and when submitting a form (sending a message from a user), data is transmitted to the server each time (the message hits the chat window accordingly). While testing locally - everything was ok. But having downloaded to the server I encountered a problem: after submitting the form, an error page 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; } ); });
While the string // return false;
commented out - throws at 404, if uncommented, the form will not submit. It is necessary for me that the data was sent at a click, but the page did not reload.
shape markup primitive
<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>
someJSON
?AjaxFormRequest();
- both parameters areundefined
.return false;
- appropriate. - Igor