欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

jquery的ajax应用实例

程序员文章站 2022-05-20 22:41:35
...
jQuery ajax的前台代码:<script type="text/javascript" src="/include/jquery/jquery-1.1.3.1.pack.js"></script>
<form name="form1" id="form1" action="ajax.php?action=1" method="post">
<input type="hidden" id="comid" name="comid" value="111">
<input type="hidden" id="jobid" name="jobid" value="222">
<input type="hidden" id="userid" name="userid" value="333">
<input type="submit" /></form>
<script language="javascript">
$("#form1").submit
(
function()
{
login();
return false;
}
);
function login()
{
var comid = $("#comid").val();
var jobid = $("#jobid").val();
var userid = $("#userid").val();
$.ajax({
type: "POST",
url: "../include/ajax.php",
data: "action=1" + "&comid=" + comid + "&jobid=" + jobid + "&userid=" + userid,
beforeSend: function(){
},
success: function(msg){
if(msg=="success"){
alert("求职信息,已经提交!请等候通知!")
}else {
alert("信息已发送,请不要重复提交!");
}
}
});
}
</script>PHP的后台代码:<?
header("Cache-Control: no-cache");
require_once("function.php");
switch ($_POST["action"]){
case 1:
$comid=verify_id($_POST["comid"]);
$jobid=verify_id($_POST["jobid"]);
$userid=verify_id($_POST["userid"]);
$appdate=time();
$hasapp=getValue("select * from csj_appjob where jobid=$jobid and userid=$userid and comid=$comid","id");
if($hasapp==""){
$sql="insert into csj_appjob(comid,jobid,userid,appdate) values($comid,$jobid,$userid,$appdate)";
query($sql);
echo "success";
}else{
echo "wrong";
}
break;
default:
break;

}
?>

更多相关文章请关注PHP中文网(www.php.cn)!

相关标签: ajax应用