ajax提交form表单,到底怎么做?急死了。用button按钮提交,不是submit
ajax提交form表单,到底怎么做?急死了。用button按钮提交,不是submit。form的id为form1,button的id为sub,注意:不是submit提交,用submit的话还用什么ajax!!!!求高手指点
$(document).ready(function(){
$('#sub').click(function(){//点击按钮提交
//要提交的表单id为form1
$('#form1').ajaxSubmit({
success:function(data){
alert(data);//参数是一个对象 而不是函数 这个返回还是是参数对象的一个方法
}
});
return false;
});
}); ajax form表单提交
[解决办法]
前提是要引用 jquery.form.js 和 jquery.js
[解决办法]
我一般怎么写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);
}