【十万火急】我想用json在前台显示验证码是否正确信息(有点用的就给分) 验证码jqueryjson 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面是个实例 别照抄 只是借鉴一下就好function check_login() { var code = $("#code").val(); if(code == "") { $("#code_msg").text("请输入验证码."); return; } $.post( "login.do", $("#myform").serialize(), function(data) { //if里面是对调回的数据进行判断 具体的判断条件你可以自己写 这个是我以前项目用的 你不用照抄 if(data.flag==1) { //验证码错误 这里是用ajax将验证码的输入项直接显示错误信息了 你要想用alert 就把这个方法改一下就好 $("#code_msg").text("验证码错误."); change(); } else { //成功 location.href = "toIndex.do"; } } ); } -----------------------------------------------------------------------------------------------------------------------十分感谢 可以在帮我看看我 我下面这段代码 哪里有错呢??? 一直调用error的方法就连alert(“请输入验证码”)都不显示-----------------------------------------------------------------------------------------------------------------------<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --><script type="text/javascript" src="<%=path%>/js/jquery-1.8.2.min.js"></script><script type="text/javascript">$(function () { $("#Verify").click(function(){ $(this).attr("src","SecurityCodeImageAction?timestamp="+new Date().getTime());}); }); $(document).ready(function(){ $("#button").click(function(){ var name= $('#id').attr('value'); if (name!=null||name!=""){ $.ajax({ url:"yangzheng", type:"post", dataType:"json", success:function(data){ if(data.msg!=null){ $("#notsuccess").html(" <br>"); var html ="成功了" ; $('#notsuccess').html(html); }else{ $("#notsuccess").html(data.msg); $("#notsuccess").css("color","red"); } }, error:function(){ alert("出现错误"); } }); }else{ alert("请填写验证码");} });});</script> </head> <body> <form id="ids" action="yanzheng" name="form" method="post"> 验证码:<input type="text" id="id" name="name" value="" /> <img src="SecurityCodeImageAction" id="Verify" style="cursor:hand;"/><font color="red">看不清?单击验证码</font> <br/> <div id="notsuccess"></div> <input type="button" id="button" name="sbt" value="进入!"/> </form> </body></html> //有必要写这么麻烦吗?var name= $('#id').attr('value');直接var name = $("#id").val();不就行了并且id是关键字啊换个id名称url:"yangzheng",这个url确定是这样? 并且像这种js错误直接用调试工具跟踪firebug或者ie8以及以上都会有js调试工具,直接就能定位哪行的错误 Spring配置文件的一些疑问 关于ssh和ssh2的问题-有点意思 只用tomcat做服务器,如何配置网站域名 如何将 项目打包成EAR包 (websphere) 怎么调试selvert? mysql 中文 插入 的2个小问题 !求9999 Struts奇怪问题,我要疯掉了,请大家帮我看看。 POST传过来数据问题高分求解 struts2 一个input,在action中怎么转换为List<String>? 在线等,在献给分!!!找不到applet类的问题?? 关于ajax在chrome,firfox下无响应的问题,在线等,100分 struts验证码验证
function check_login() {
var code = $("#code").val();
if(code == "") {
$("#code_msg").text("请输入验证码.");
return;
}
$.post(
"login.do",
$("#myform").serialize(),
function(data) {
//if里面是对调回的数据进行判断 具体的判断条件你可以自己写 这个是我以前项目用的 你不用照抄
if(data.flag==1) {
//验证码错误 这里是用ajax将验证码的输入项直接显示错误信息了 你要想用alert 就把这个方法改一下就好
$("#code_msg").text("验证码错误.");
change();
} else {
//成功
location.href = "toIndex.do";
}
}
);
}
十分感谢 可以在帮我看看我 我下面这段代码 哪里有错呢??? 一直调用error的方法
就连alert(“请输入验证码”)都不显示
-----------------------------------------------------------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="<%=path%>/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function () {
$("#Verify").click(function(){
$(this).attr("src","SecurityCodeImageAction?timestamp="+new Date().getTime());
});
});
$(document).ready(function(){
$("#button").click(function(){
var name= $('#id').attr('value');
if (name!=null||name!=""){
$.ajax({
url:"yangzheng",
type:"post",
dataType:"json",
success:function(data){
if(data.msg!=null){
$("#notsuccess").html(" <br>");
var html ="成功了" ;
$('#notsuccess').html(html);
}else{
$("#notsuccess").html(data.msg);
$("#notsuccess").css("color","red");
}
},
error:function(){
alert("出现错误");
}
});
}else{
alert("请填写验证码");}
});
});
</script>
</head>
<body>
<form id="ids" action="yanzheng" name="form" method="post">
验证码:<input type="text" id="id" name="name" value="" />
<img src="SecurityCodeImageAction" id="Verify" style="cursor:hand;"/><font color="red">看不清?单击验证码</font>
<br/>
<div id="notsuccess"></div>
<input type="button" id="button" name="sbt" value="进入!"/>
</form>
</body>
</html>
//有必要写这么麻烦吗?
var name= $('#id').attr('value');
直接
var name = $("#id").val();
不就行了
并且id是关键字啊换个id名称
url:"yangzheng",
这个url确定是这样?
直接用调试工具跟踪
firebug或者ie8以及以上都会有js调试工具,直接就能定位哪行的错误