jQuery的ajax如何根据其返回内容,选择不同的结果
$().ready(function () {
$("#xx1").click(function () {
$.ajax({
type: "GET",
url: "/check/checkcode.ashx",
dataType: "html",
data: "code=" + $("#xxx").val(),
beforeSend: function (XMLHttpRequest) { },
success: function (msg) {
return confirm("确定");
}
});
});
});
比方说如果msg==1的话,return confirm("xxx");可是return confirm以后不管确定还是取消,button.click还是继续了
,我想他如果返回一个值的话,可以禁止其提交,该怎么实现呢,
$().ready(function () {
$("#xx1").click(function () {
$.ajax({
type: "GET",
url: "/check/checkcode.ashx",
dataType: "html",
data: "code=" + $("#xxx").val(),
beforeSend: function (XMLHttpRequest) { },
success: function (msg) {
return confirm("确定");
}
});
});
});
比方说如果msg==1的话,return confirm("xxx");可是return confirm以后不管确定还是取消,button.click还是继续了
,我想他如果返回一个值的话,可以禁止其提交,该怎么实现呢,
{}
else
{ return false; }前台调用这个JS方法
if (window.confirm("是否执行?")) {
$.ajax({
type: "GET",
url: "/check/checkcode.ashx",
dataType: "html",
data: "code=" + $("#xxx").val(),
beforeSend: function (XMLHttpRequest) { },
success: function (msg) {
if (msg != 0) {
alert("Success!");
}
else {
alert("Error!");
}
}
});
}
else {
return false;
}
success中
if(confirm("确定"))
{
这里执行
}
else
{
return false;
}
让你改submit到button,你改了?
改了就有效了哇~
你用ajax提交,不需要一定是submit的。