...

The form still returns false return messages in JS

It #frmToDostill seems to support feedback

<form id="frmToDo" name="frmToDo">
    ...
    <a id="btnSubmit" href="javascript:document.frmToDo.submit();">Add</a>

google.load("jquery", 1);
google.load("jqueryui", 1);

google.setOnLoadCallback(function() {
    ...

    $("#frmToDo").submit(function() {
        return false;
...

why does this happen? maybe because of href="javascript:document.frmToDo.submit(). how can I submit the form using this link (I didn’t use it <input type="submit" />because of design problems, it seems that the buttons are harder in style, esp in different browsers), is there an AJAX method?

+3
source share
4 answers

you say you didn’t use it <input type="submit" />because of the style, so why not use it,

<a id="btnSubmit" href="#" onclick="return false">Add</a>

google.setOnLoadCallback(function() {

   //...OTHER LOGIC

      $('#btnSubmit').click(function(){
          var form = $(this).parent().find('form');
          var formdata = $(form).serialize();
          $.ajax({
             url : 'ajax/receiver.php',
             data : formdata,
             success : function(responce)
             {
                alert(responce); // do what you want here
             }
          })
      });
   //...OTHER LOGIC
});
+3
source
$('#btnSubmit').click(function(){
    $("#frmToDo").submit();
})

use this as a click handler on <a>

+1
source

ajax-, submit . "" . ajax.

http://api.jquery.com/jQuery.ajax/

0

As mentioned above, you can simply attach to the event directly by clicking. However, if you want to use your method, you can also do this.

I think that since you are attaching to the event through the DOM API and not using the built-in function, you need to explicitly cancel this event, and not just return false, at least to represent the form. I believe this should work for you.

$('#frmToDo').submit(function(e){
  e.preventDefault();
});
0
source

Source: https://habr.com/ru/post/1747858/


All Articles