jQuery ajax的前台代码编写
Posted 服务器-老张
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery ajax的前台代码编写相关的知识,希望对你有一定的参考价值。
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(2881064151){
},
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;
}
?>
以上是关于jQuery ajax的前台代码编写的主要内容,如果未能解决你的问题,请参考以下文章
编写自己的javascript功能库之Ajax(仿jquery方式)