0

I have a form that shall be submitted via ajax while the form action shall be prevented. I tried e.preventDefault() and return false but still the form data gets attached as get parameters in URL thus not preventing the default action.

Can default action even be prevented with obtrusive Javascript/JQ? Am I doing something wrong with sending the event object? Can someone point me towards the solution please. Thanks a lot!

HTML

<form id="filter_form" onsubmit="Sending(e)" action="<?php echo URL::action('countries@anyIndex'); ?>">

JQ:

function Sending(e) {
frm = $("#filter_form");
term = $('#filter_name').val();
$.ajax({
    type: "POST",
    url: $(frm).attr('action'),
    data: {term: term},
    success: function(data) {
        $("#list").html(data.list);
    },
    dataType: "json"
});
e.preventDefault();
}
Hobby99
  • 703
  • 2
  • 14
  • 35

0 Answers0