ajax为什么会提交两次,ajax需要两次提交才能成功

/**

* Created by Demon-pro on 2015/7/27.

*/

var recharge = function () {

function clientRechargeValidate() {

//校验是选择或者填写充值金额

var money = getOrPayMoney();

if (money == 0) {

alert("充值金额不能为空");

return false;

}

var orUserTypeShow = getOrUserType();

if (orUserTypeShow == 1 && money < 30000) {

alert("申请开店,至少充值30000元")

return false;

}

return true

}

//获取充值金额

function getOrPayMoney() {

var orPayMoney = 0;

$("li[name=orPayMoney]").each(function () {

if ($(this).hasClass("sss")) {

orPayMoney = parseFloat($(this).html(), 2);

}

})

if (orPayMoney != 0) return orPayMoney;

var otherMoney = $("#otherMoney").val()

if (otherMoney.trim() != "") {

orPayMoney = parseFloat(otherMoney, 2);

}

return orPayMoney;

}

//获取商户类型,开店,普通充值

function getOrUserType() {

var orUserType = 1;

$("li[name=orUserType]").each(function () {

if ($(this).hasClass("sss")) {

orUserType = $(this).val();

}

})

return orUserType;

}

return {

init: function () {

//客户类型绑定事件 1 开店 2 会员

$("li[name=orUserType]").click(function () {

$("#otherMoney").val("");

var orUserType = $(this).val();

if (orUserType == dict.orUserType2) {

$("li[name=orPayMoney]").show();

return;

}

//循环支付金额按钮

$("li[name=orPayMoney]").each(function () {

//只显示30000的标签

var money = $(this).html();

if (money == 30000) {

$(this).show();

} else {

$(this).hide();

}

})

$("li[name=orPayMoney][html='30000']").show()

})

$("li[name=orPayMoney]").click(function () {

$("#otherMoney").val("");

})

},

clientRecharge: function (orPayType) {

if (!clientRechargeValidate()) {

return;

}

var money = getOrPayMoney();

var type = orPayType == 1 ? "微信" : "支付宝";

var orUserTypeShow = getOrUserType() == 1 ? ",申请开店" : "";

if (!confirm("您确定" + type + "充值" + money + "元" + orUserTypeShow))return;

var object={

orStatus:2,

orPayType:orPayType,

orUserType:getOrUserType(),

orPayMoney:getOrPayMoney()

}

$.ajax({

url: basePath + "recharge/clientRecharge",

data: JSON.stringify(object),

contentType: "application/json; charset=utf-8",

type: "post",

success: function (data) {

if (data.ok) {

formSub(basePath + "recharge/clientRechargeSuccess?id="+data.returnMsg);

} else if (data.error) {

alert(data.returnMsg);

return false;

}

}

});

}

}

}();

var basePath = (function () {

var url = window.location + "";

var h = url.split("//");

var x = h[1].split("/");

return h[0] + "//" + window.location.host + "/" + x[1] + "/";

})();

function formSub() {

var $form = $("form");

if ($form.size() == 0) {

$("body").wrap('

');

$form = $("form");

}

switch (arguments.length) {

case 0:

$form.attr("method", "post").submit();

break;

case 1:

$form.attr("method", "post").attr("action", arguments[0]).submit();

break;

case 2:

arguments[0].attr("method", "post").attr("action", arguments[1]).submit();

break;

}

}

var dict = {

//商户

orUserType1: 1,

//vip

orUserType2: 2,

//支付状态 1 待支付 2 已支付,3支付成功

orStatus1: 1,

orStatus2: 2,

orStatus3: 3

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值