注册商圈
/**
*
* V1.0
*/
$(document).ready(function() {
//驗證商圈名
$(" #businessName").blur( function(){
varbusinessName=$("#businessName").val()
if(businessName!=""){
$("#businessName_error"). html("");
}else{
$("#businessName_error "). attr("class","error_div").html("
" "商圈名不能為空! ");
}
});
//驗證商圈英文名稱
$("#businessEname").blur(function(){
varbusinessEname=$( "#businessEname").val()
if(businessEname!=""){
$("#businessEname_error").html("
");
}else{
$("#businessEname_error").attr("class", "error_div").html("" "商圈英文名稱不能為空! );
//上傳圖片及資料儲存
$("#imgSave").click(function(){
var ext = '.jpg. jpeg.gif.bmp.png.';
var f=$("#file").val();
if (f== "") {//先判斷是否已選擇了檔案
$("#file_error").attr ("class","error_div").html("
" "請新增商圈logo ! .' f '.') == -1) {
$("#file_error").attr("class","error_div").html("" "圖片格式不正確! >url: "${ctx}/upload/upload.do",
dataType: 'json',
contentType: "application/json ; charset=utf-8",
success: function(data ) {
// 'data' 是代表評估的json 資料的物件
//如果上傳圖片成功則儲存表單註冊資料
if(data.status=="0"){
var fileName=data.fileName;
//alert(檔名);
varbusinessName=$("#businessName").val();
var userId=$("#userId").val ();
varbusinessEname=$("#businessEname").val();
businessName=encodeURI(businessName);
businessName=encodeURI(businessName);
var urls="${xvar. }/business/addBusiness.do?businessName="businessName"&businessPic="fileName"&businessEname="businessEname"&userId="userId;
$.ajax({
type: "post",
url: urls ,
dataType: "json", /*這句話可用不用,沒有影響*/
contentType: "application/json; charset=utf-8",
成功: function (data) {
if(data.status=="0"){
alert("註冊成功!")
}else{
alert("註冊失敗!原因是:"
}
},
錯誤: function (XMLHttpRequest, textStatus, errorThrown) {
alert (錯誤拋出);
}else{
$("# file_error").attr("class","error_div").html("
" data .message);
}
}
};
// 提交表單
$('#uploadImgForm').ajaxSubmit(options);
});🎜>}; );
腳本>
身體>