完整代碼:php
function checkjob(){
var userName = $("#layer_mess input[name=userName]").val();
var userSex = $("#layer_mess input[name=userSex]:checked").val();
var userAge = $("#layer_mess input[name=userAge]").val();
var userDegree = $("#layer_mess input[name=userDegree]").val();
var userSchool = $("#layer_mess input[name=userSchool]").val();
var userHomepage = $("#layer_mess input[name=userHomepage]").val();
var userPhone = $("#layer_mess input[name=userPhone]").val();
var userEmail = $("#layer_mess input[name=userEmail]").val();
var city = $("#layer_mess input[name=city]:checked").val();
var userWorkyear = $("#layer_mess input[name=userWorkyear]").val();
var specialty = $("#layer_mess input[name=specialty]").val();
var deal = $("#layer_mess input[name=deal]").val();
var userWorks = $("#layer_mess textarea[name=userWorks]").val();
var userPost = $("#layer_mess input[name=userPost]").val();
var closeObj = $(".xubox_close");
if(userName == ''){
alert('姓名不能爲空!');
$("#layer_mess input[name=userName]").select();
return false;
}
if(userPhone == ''){
alert('聯繫電話不能爲空!');
$("#layer_mess input[name=userPhone]").select();
return false;
}
if(userEmail == ''){
alert('Email不能爲空!');
$("#layer_mess input[name=userEmail]").select();
return false;
}else{
var myemail = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
if(!myemail.test(userEmail)){
alert('Email格式錯誤!');
$("#layer_mess input[name=userEmail]").select();
return false;
}
}html
var data = {
name: name,
sex: sex,
cardno: cardno,
birth: birth,
email: email,
grade: grade,
school: school,
homephone: homephone,
parentmobile: parentmobile,
parentemail: parentemail,
address: address,
zhusu: zhusu,
shenqingjiudu: shenqingjiudu,
jianhuren: jianhuren,
cmd: 'baoming'
};
$.ajax({
type: 'POST',
data: data,
dataType: 'json',
url: 'ajax.php',
error: function(XMLHttpRequest, textStatus, errorThrown) {},
success: function(msg) {ajax
// msg.no == 1 :這個是根據後端定義的值no=1的時候,是操做成功。
if (msg.no == 1) {
alert(msg.msg);json
//若是符合條件,則清空#apply input的內容
$("#apply input").val("");
return;
} else {
alert(msg.msg);
return false;
}
}
});後端
error:function (XMLHttpRequest, textStatus, errorThrown){} 釋義:app
這是一個 Ajax 事件。url
(默認: 自動判斷 (xml 或 html)) 請求失敗時調用時間。xml
參數有如下三個:XMLHttpRequest 對象、錯誤信息、(可選)捕獲的錯誤對象。htm
若是發生了錯誤,錯誤信息(第二個參數)除了獲得null以外,還多是"timeout", "error", "notmodified" 和 "parsererror"。
textStatus:
"timeout", "error", "notmodified" 和 "parsererror"。 對象