使用FORM,禁用默认提交,使用ajax提交,目的是使用Validform FORM验证插件,实践证明,没有达到目的,未通过验证,仍然被提交了

前端之家收集整理的这篇文章主要介绍了使用FORM,禁用默认提交,使用ajax提交,目的是使用Validform FORM验证插件,实践证明,没有达到目的,未通过验证,仍然被提交了前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<include file="Public:top"/>
<script type="text/javascript">
var demo=$("#MyForm").Validform();
</script>

<body>
<div class="head">
	<include file="Public:headtop" />
    
	<div class="headwrap clear">
    		<div class="logo"><a href="__ROOT__"><img src="__PUBLIC__/images/will_07.jpg" /></a></div>	
            
    </div>
    
   <div class="menu">
    		<div class="headwrap">
            		<span class="cur"><a href="{:U('Problem/index')}">网站帮助</a></span><img src="__PUBLIC__/images/will_21.jpg" />
                    
            </div>
    </div>
</div>
<!--end head--> 


<script type="text/javascript">
	$(function(){
				$(".exeBox,.clickpic").click(function(){
						$(this).next().show();
						shadow();	
					});
				$(".edittitle span").click(function(){
						$(this).parents(".editBox").hide();
						$(".wrapbg").remove();
					})
			})
</script>
<div class="organ">
	<div class="organl nobg">
    	<div class="classify">
        		<span>问题类别</span>
                <ul>
				<volist name="cats" id="vo">
                	<li><a href="{:U('Problem/Cat',array('cid'=>$vo['cat_id']))}">{$vo.name}</a></li>
				</volist>
                </ul>
        </div>
    </div>
    <!--end organl-->
    <div class="organr">
        <div class="setbase"><br />
        	 <div class="mesgc">
             		<span id="my_menu" class="newnav">{$cid|get_problem_cat_name}</span> 
					<empty name="user">
					<span onclick="forbid_submit()" class="newnav">举报不良信息</span>
					<else /> 
					<span onclick="display_report_Box2()" class="newnav">举报不良信息</span>
					</empty>
                    <div class="memberindex_sixin margintop20">
					<if condition="$user.user_id eq ''">					
					<a onclick="forbid_submit()" href="javascript:;">我要提问</a>
					<else />					
					<a onclick="display_ask_Box()" href="javascript:;">我要提问</a>
					</if>					
					</div>
            </div>
           	
            
            <div class="mesgcenter" >
            		<div class="baseset"><br />
						<volist name="list" id="vo">
                    	<div class="fabulist indexcenter">
                        		<div class="floatl mrbu">
                         		<a href="#" class="fabuimg"><img src="{$vo.user_id|getAvatar}"></a>
                                <p><a href="#">{$vo.user_id|getUserName}</a></p>
                                <p onclick="display_answer_Box({$vo.problem_id})"><img src="__PUBLIC__/images/organ/q_11.png" />{$vo.title}</p>
                                </div>
                                <div class="fabutext">
                                    <div class="clear"><a href="#" class="indexcentertime">{$vo.addtime|showDate}</a></div>
                                  	<div class="clear"><a onclick="display_answer_Box({$vo.problem_id})" href="javascript:;" class="indexcentertime blue">回复({$vo.problem_id|get_problem_answer_num})</a></div>
								</div>
                        </div>
                        </volist>
						
                        
                        
                      <br />
                        <br />

                         
                         <div class="pages" style="text-align:right;">
                         		{$page}
                         </div>
                      <br /><br />
                   </div>
            </div>
            
            
            
            
            
               
               
        </div>
    </div>
     <!--end organl-->
    
    
</div>
<div id="my_Box"></div>	
<include file="Public:footer"/>
<script type="text/javascript">

  
  
  
  
  
  
  
  


function display_ask_Box()
{
	var url = "{:U('Problem/getAjaxCats')}";
	$.get(
		url,function(data)
		{			
			display_ask_Box2(data.data);
		}
	);
	
}

function display_answer_Box(problem_id)
{
	var url = "{:U('Problem/getAnswerBoxData')}";
	
	$.get(
		url,{
			problem_id:problem_id
		},function(data)
		{			
			display_answer_Box2(data.data);
		}
	);
	
}

/*提交举报的不良信息*/
function save_report()
{
	var arr = new Array();
	var url = U("Problem/saveReport",arr,false);
	var web = $("#rweb").val();
	var content = $("#rcontent").val();
	var contact = $("#rcontact").val();
	var phone = $("#rphone").val();
	
	/*alert(url);
	alert(web);
	alert(content);
	alert(contact);
	alert(phone);*/
	
	$.post(
		url,{
			web : web,content : content,contact : contact,phone : phone
		},function(data)
		{
			alert(data.info);
			$("#my_Box").html('');
		}
	);
	
	return false;
}

/*举报不良信息弹出框
 *实现了功能,但是cdc已经做了这个。我这个就是多余的了。
 */
function display_report_Box2()
{	
	
	
	
	var Box = '<form id="MyForm" onSubmit="return save_report();">';
	Box += '<div class="editBox" style="display:block">';
	Box += '<div class="edittitle noborder">';
	Box += '<h3>举报不良信息</h3><span><img src="__PUBLIC__/images/self_03.jpg" /></span>';
	Box += '</div>';
	Box += '<div class="editBoxtable">';
	Box += '<table cellpadding="0" cellspacing="0" border="0" class="indexsetpic">';
	Box += '<tr>';
	Box += '<td width="105" style="text-align:right">举报网址:</td>';
	Box += '<td><input type="text" class="custext" id="rweb" datatype="s1-16" errormsg="标题至少1个字符,最多16个字符!" nullmsg="请填写标题"/></td>';
	Box += '</tr>';
	Box += '<tr>';
	Box += '<td  style="text-align:right">举报内容:</td>';
	Box += '<td><textarea class="tabletextarea"  id="rcontent"></textarea></td>';
	Box += '</tr>';
	Box += '<tr>';
	Box += '<td  style="text-align:right;vertical-align:top;">举报人:</td>';
	Box += '<td>';
	Box += '<input type="text" class="custext" id="rcontact"/>';
	Box += '</td>';
	Box += '</tr>';
	Box += '<tr>';
	Box += '<td  style="text-align:right;vertical-align:top;">联系方法:</td>';
	Box += '<td>';
	Box += '<input type="text" class="custext" id="rphone"/>';
	Box += '</td>';
	Box += '</tr>';
	Box += '';
	Box += '<tr>';
	Box += '<td></td>';
	Box += '<td> <input type="submit" value=" 提交 " class="basesubmit"/></td>';
	Box += '</tr>';
	Box += '</table>';
	Box += '<div class="editBoxsubmit">';
	Box += '';
	Box += '</div>';
	Box += '</div>';
	Box += '</div>';
	Box += '</form>';
	
	$("#my_Box").html(Box);
	var demo=$("#MyForm").Validform();
	remove_Box();
}


function display_answer_Box2(data2)
{
	//alert(data2[0]['cat_name']);return false;
	var Box = '<div class="editBox" style="display:block;height:695px;position:absolute;">';
	Box += '<div class="edittitle noborder">';
	Box += '<span><img src="__PUBLIC__/images/self_03.jpg" /></span>';
	Box += '</div>';
	Box += '';
	Box += '<div class="editBoxtable questable">';
	Box += '<div class="questitle">网站帮助</div>';
	Box += '<div class="ques">';
	Box += '<div class="questop">';
	Box += '<span><img src="__PUBLIC__/images/organ/q_11.png" />';
	Box += data2[0]['title'];
	Box += '</span>';
	Box += '<em>问题类别:<a href="javascript:;">';
	Box += data2[0]['cat_name'];
	Box += '</a></em>';
	Box += '</div>';
	Box += '<p><a href="javascript:;">';
	Box += data2[0]['user_name'];
	Box += '</a>|';
	Box += data2[0]['addtime'];
	Box += '</p>';
	Box += '</div><br />';
	Box += '<div class="questitle">我来帮他解答</div>';
	Box += '<div class="quseedit">';
	Box += '<textarea id="content" class="tabletextarea"></textarea><input type="hidden"  value="' + data2[0]['problem_id'] + '" id="problem_id" />';
	<if condition="$user.user_id eq ''">
	Box += '<p><input onclick="forbid_submit()" type="button" class="selfsend" value="提交回答" style="font-size:14px"/></p>';
	<else />
	Box += '<p><input onclick="saveAnswer()" type="button" class="selfsend" value="提交回答" style="font-size:14px"/></p>';
	</if>
	Box += '</div>';
	Box += '';
	
	var data3 = data2[1];
	$.each(data3,function(i){
		Box += '<div class="answerq">';
		Box += '<a href="#">' + data3[i]['poster'] + '</a>';
		Box += '<em>' + data3[i]['addtime'] + '</em>';
		Box += '<p><img src="__PUBLIC__/images/organ/qcheck_11.jpg" />' + data3[i]['content'] + '</p>';		
		Box += '</div>';
	});	
	Box += '';
	Box += '';
	Box += '</div>';
	Box += '';
	Box += '';
	Box += '';
	Box += '</div>';
	
	$("#my_Box").html(Box);
	remove_Box();
}

function display_ask_Box2(data2){
	
  	var Box = '<div class="editBox" style="display:block;height:435px;">';
	Box += '<div class="edittitle noborder">';
	Box += '<h3>我要提问</h3><span><img src="__PUBLIC__/images/self_03.jpg" /></span>';
	Box += '</div>';
	Box += '<div class="editBoxtable">';
	Box += '<table cellpadding="0" cellspacing="0" border="0" class="indexsetpic">';
	Box += '<tr>';
	Box += '<td width="105" style="text-align:right">问题类别:</td>';
	Box += '<td><select id="cat_id" name="cat_id">';
	$.each(data2,function(i){
			Box += '<option value="' + data2[i]['cat_id'] + '">' + data2[i]['name'] + '</option>';
		});
	Box += '</select></td>';
	Box += '</tr>';
	Box += '<tr>';
	Box += '<td width="105" style="text-align:right">标题:</td>';
	Box += '<td><input id="title" type="text" class="custext"/></td>';
	Box += '</tr>';
	Box += '<tr>';
	Box += '<td  style="text-align:right">问题内容:</td>';
	Box += '<td><textarea id="content" class="tabletextarea"></textarea></td>';
	Box += '</tr>';
	Box += '';
	Box += '';
	Box += '<tr>';
	Box += '<td></td>';
	Box += '<td> <input onclick="saveProblem()" type="button" value=" 提交 " class="basesubmit"/></td>';
	Box += '</tr>';
	Box += '</table>';
	Box += '<div class="editBoxsubmit">';
	Box += '';
	Box += '</div>';
	Box += '</div>';
	Box += '</div>';
	
	$("#my_Box").html(Box);

  remove_Box();
}

function saveProblem()
  {
	  var url = "{:U('Problem/saveProblem')}";
	  var cat_id = $("#cat_id").val();
	  var title = $("#title").val();
	  var content = $("#content").val();
	  
	  $.post(url,{
			cat_id:cat_id,title:title,content:content
		},function(data)
		{
			alert(data.info);
			hidden_Box();
			location.reload();
		}
	  );
}

/*保存回答*/
function saveAnswer()
  {
	  var url = "{:U('Problem/saveAnswer')}";
	  var problem_id = $("#problem_id").val();
	  var content = $("#content").val();  
	  
	  $.post(url,{
			problem_id:problem_id,function(data)
		{
			alert(data.info);
			hidden_Box();
			location.reload();
		}
	  );
}


/**
 *关闭弹窗
 */
function remove_Box()
{
	$(".edittitle span").click(function(){
		$(this).parents(".editBox").hide();
		$(".wrapbg").remove();
		})
}

/**
 *弹窗自动消失
 */
function hidden_Box()
{
	$(".edittitle span").parents(".editBox").hide();
		$(".wrapbg").remove();
		
}

/**
 *未登录禁止提交
 */
function forbid_submit()
{
	alert("请登录!");
}
</script>
原文链接:https://www.f2er.com/ajax/164855.html

猜你在找的Ajax相关文章