日期:2014-05-16  浏览次数:20627 次

jquery 中的ajax页面无刷新提交方法

js代码
function checkName()
{
var value = encodeURIComponent(encodeURIComponent($.trim($("#hnbIdentifier").val())));

if ("" == value)
{
$("#staError").html("");
}
else
{
$.ajax(
{
type : 'POST',
url : 'checkHnbIdentifier',
data : 'hnbIdentifier=' + value,
success : function(msg)
{
if ("true" == msg)
{
$("#staError").html("该基站标识已存在!");
$("#hnbIdentifier").focus();
$("#hnbIdentifier").select();
}
else
{
$("#staError").html("");
}
},
error : function(msg, textStatus, e)
{
alert("当前登录用户失效,请重新登录。");
window.location = path + "/login.jsp";
}
});
}
}


jsp代码:
<tr>
    <td width="25%" height="30" align="center" class="borderbottomright">基站标识</td>
    <td width="75%" class="borderbottom"><label>
      <input name="hnbIdentifier" type="text" id="hnbIdentifier" value="" style="width: 310px;" onblur="checkName();"/>
      <FONT SIZE="" COLOR="red">*</FONT>
      <span id="staError" style="font-size: 9pt; font-family: 黑体; color: red"></span>
    </label></td>
  </tr>