Question: I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code?
This is my form:

```
<form class="ajax" action="/../addchannel/createUser.php" method="post" >
<input type="text" name="userName" placeholder="userName"><br>
<input type="text" name="email" placeholder="email"><br>
<input  type="submit" value="submit" >
</form>';

```

And this is my script:

```
$('form.ajax').on('submit', function () {
    var that = $(this),
        url = that.attr('action'),
        type = that.attr('method'),
        data = {};

    that.find(['name']).each(function (index, value)) {
        var that = $(this),
            name = that.attr('name'),
            value = that.val();
        data[name] = value;
    });
$.ajax({
    url: url,
    type: type,
    data: data,
    success: function (response) {
        consol.log(response)
    }
});
});

```

Answer: 
You forgot `return false` at the end or prevent default.

```
 $('form.ajax').on('submit', function (event) {
    event.preventDefault();
var that = $(this),
    url = that.attr('action'),
    type = that.attr('method'),
    data = {};
   ....
  //or return false;

});

```
Use [event.preventDefault()](http://api.jquery.com/event.preventDefault/)

```
$('form.ajax').on('submit', function (e) {
    e.preventDefault();
    //code here
});

```