php使用jquery ajax提交表单提交,与AJAX PHP JQuery的提交表单带我到操作页面(Submit Form with AJAX...

我想提交此表而无需刷新页面,但是当我提出需要我来操作页面。 什么是错我的代码? 这是我的表格:

';

这是我的脚本:

$('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 1:

通过事件作为参数,并使用event.preventDefault()

$('form.ajax').on('submit', function (e) {

e.preventDefault();

Answer 2:

ü忘记return false在年底或防止违约。

$('form.ajax').on('submit', function (event) {

event.preventDefault();

var that = $(this),

url = that.attr('action'),

type = that.attr('method'),

data = {};

....

//or return false;

});

Answer 3:

使用e.preventDefault()或return false; 防止表单提交

$('form.ajax').on('submit', function (e) {//Pass the event argument here

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)

}

});

e.preventDefault();

//OR

return false;

});

Answer 4:

使用event.preventDefault()

$('form.ajax').on('submit', function (e) {

e.preventDefault();

//code here

});

Answer 5:

使用jQuery AJAX是不会阻止浏览器跟随窗体动作页。 要做到这一点,你应该避免浏览器通过简单的函数来做到这一点: e.preventDefault()

这里是你的代码:

//Pass the event argument (e)

$('form.ajax').on('submit', function (e) {

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)

}

});

//Prevent Browser to follow form action link:

e.preventDefault();

//you can use also

// return false;

});

Answer 6:

尝试这个..

Submit

function mail()

{

var name = $("#user_name").val();

var email = $("#email").val();

$.ajax({

type: "POST",

url: "contact.php",

data: "name=" + name+"&customer_mail="+email,

success: function(html) {

//do ur function

}

});

}

文章来源: Submit Form with AJAX PHP JQuery takes me to action page

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值