ajax提交form表单,到底怎么做?急死了。用button按钮提交,不是submit ajaxform表单提交 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ajax提交表单,最简单的那种,不过不用submit而是button,button的id为sub,form表单的id为form1,post方式提交。我不会ajax 手写一段ajax吧 可能有错误$(function(){ $('#sub').click(function(){//点击按钮提交 //要提交的表单id为form1 $.ajax({ url:"xxxxx", data:$("#form1").serialize(), type:"post", success:function(data){//ajax返回的数据 } }); });}); //保存 $('#BtnSave').click(function () { var previewOptions = { beforeSubmit: validateForm, url: '/ContentVerify/DoCreateOrEdit', type: 'POST', dataType: 'json', success: function (result) { if (result.Success) { ShowMsg("保存成功!", "/ContentVerify/Index"); } else { ShowMsg("保存失败!" + result.Msg); } }, iframe: false }; $('#doform').ajaxSubmit(previewOptions); return false; }); 前提是要引用 jquery.form.js 和 jquery.js url这部分怎么写,我用的是php,action是一个对象的方法 这个简单你ajax完了之后 调用form的submit $.ajax({ url:"xxxxx", data:$("#form1").serialize(), type:"post", success:function(data){//ajax返回的数据 } });$("#form1").submit();记住用此调用时你的HTML的form里不能有<input type = 'submit' />submit按钮 不然你点button就会刷新页面 url这部分怎么写,我用的是php,action是一个对象的方法我一般怎么写Interface.php写接口然后data传入参数 找到Interface.php这个文件里面的你想调用的函数这里我传入"GetJoke"$.ajax({ type : "POST", url : "../php/Interface.php", data : { Index : "GetJoke", curpage : curpage, countPerPage : countPerPage, joketype : joketype }, dataType : "json", async : false, success : function(data) {}Interface.php$index = $_POST["Index"];switch ($index) { case 'GetJoke' : GetJoke(); break;}function GetJoke() { $curpage = $_POST['curpage']; $joketype = $_POST['joketype']; $CountPerPage = $_POST['countPerPage']; $sidx = 'uploaddate'; $sord = 'desc'; $where = '1=1'; $where .= " AND joketype = '" . $joketype . "'"; $clsSql = new UserOp(); $result = $clsSql -> GetJoke($curpage, $CountPerPage, $sidx, $sord, $where); echo json_encode($result);} $.ajax({ url : "", 请求的Url data : { }, 参数Json格式 dataType : "json", 请求的返回类型 这里为json type : "post", 提交方式 cache : false, 是否异步提交 success : function(result) { alert('回调函数'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('错误处理'); }}); 我来贴一段我写的java版本的ajax登录提交 $.ajax({ type:"get", url:"vote.do?action=ajaxLoginSys&r="+Math.random(), contentType:"application/x-www-form-urlencoded; charset=GBK", data:{user_name:user_name,pass_word:pass_word}, dataType:"text", success:function(data){ flag = true; $("#loginflag").val("1");//设置登录标志位 changeHtml(data); }//success });//Ajax 关于用js动态设计css里面的属性值 JS折叠怎么默认显示一个 麻烦高手看一下 关于多个SWF间共享元件遇到的问题,多域关系,本地外网有差别? 怎麼實現創建div可以不改變當前的頁面佈局,而在指定位子的上層 向自己模拟实现一个树的通用js,遇到个大问题 菜鸟级问题:换行符 100分求教,在页面间跳转时,当第二个页面没有加载全时显示一中间过渡页面,当第二个页面加载全时显示第二个页面 extjs URL请求包含中文问题 Bootstrap table鼠标停留行悬浮效果 新手 求教一个事件 的父子继承关系的问题 关于QQ非会员克隆好友的可能性(有部分进展)
//要提交的表单id为form1
$.ajax({
url:"xxxxx",
data:$("#form1").serialize(),
type:"post",
success:function(data){//ajax返回的数据
}
});
});
});
//保存
$('#BtnSave').click(function () {
var previewOptions = {
beforeSubmit: validateForm,
url: '/ContentVerify/DoCreateOrEdit',
type: 'POST',
dataType: 'json',
success: function (result) {
if (result.Success) {
ShowMsg("保存成功!", "/ContentVerify/Index");
}
else {
ShowMsg("保存失败!" + result.Msg);
}
},
iframe: false
}; $('#doform').ajaxSubmit(previewOptions);
return false;
});
url:"xxxxx",
data:$("#form1").serialize(),
type:"post",
success:function(data){//ajax返回的数据
}
});
$("#form1").submit();记住用此调用时你的HTML的form里不能有<input type = 'submit' />submit按钮 不然你点button就会刷新页面
我一般怎么写Interface.php写接口
然后data传入参数 找到Interface.php这个文件里面的你想调用的函数
这里我传入"GetJoke"
$.ajax({
type : "POST",
url : "../php/Interface.php",
data : {
Index : "GetJoke",
curpage : curpage,
countPerPage : countPerPage,
joketype : joketype
},
dataType : "json",
async : false,
success : function(data) {}
Interface.php
$index = $_POST["Index"];
switch ($index) {
case 'GetJoke' :
GetJoke();
break;
}
function GetJoke() {
$curpage = $_POST['curpage'];
$joketype = $_POST['joketype'];
$CountPerPage = $_POST['countPerPage'];
$sidx = 'uploaddate';
$sord = 'desc';
$where = '1=1';
$where .= " AND joketype = '" . $joketype . "'"; $clsSql = new UserOp();
$result = $clsSql -> GetJoke($curpage, $CountPerPage, $sidx, $sord, $where);
echo json_encode($result);
}
url : "", 请求的Url
data : { }, 参数Json格式
dataType : "json", 请求的返回类型 这里为json
type : "post", 提交方式
cache : false, 是否异步提交
success : function(result)
{
alert('回调函数');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('错误处理');
}});
type:"get",
url:"vote.do?action=ajaxLoginSys&r="+Math.random(),
contentType:"application/x-www-form-urlencoded; charset=GBK",
data:{user_name:user_name,pass_word:pass_word},
dataType:"text",
success:function(data){
flag = true;
$("#loginflag").val("1");//设置登录标志位
changeHtml(data);
}//success
});//Ajax