当前位置: 代码迷 >> JavaScript >> $.post返回页面带有<script>标签的div元素解析,拿不到<script>标签解决方法
  详细解决方案

$.post返回页面带有<script>标签的div元素解析,拿不到<script>标签解决方法

热度:409   发布时间:2013-10-21 17:00:48.0
$.post返回页面带有<script>标签的div元素解析,拿不到<script>标签
JSP页面源码:

<%@ page contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true" import="java.io.*,java.util.*"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html id="htmlObject">
<head>
<title>123</title>
<%@ include file="/common/resource.jsp"%>
<script type="text/javascript">
$(document).ready(function(){
htmlTest();
});
function htmlTest() {
alert($("#valiSource").html());
}
function languageSelecter_onChanged(control) {
$control=$(control);
$form = $("#form-login");
$.post($control.attr("href"), $form.serialize(), function(html) {
//修改ajax加载为局部form-login加载,避免整个html中head部分文件资源重加载
$html=$(html);
//alert(html);
alert($html.find("#valiSource").html());
$("#divForm").html($html.find("#divForm").html());
//$("body").html(html);
$form.validationEngine({
autoPositionUpdate:true,
focusFirstField:true,
scroll:true
});
});
return false;
}
</script>
</head>
<body>
<form id="form-login" action="login!login.action" successAction="index.action" method="post">
<div id="divForm" align="center">
<div id="valiSource">
aaa
<script src="${ctx}/static/jquery-Validation-Engine/js/languages/jquery.validationEngine-${sessionScope.WW_TRANS_I18N_LOCALE}.js" type="text/javascript"></script>
</div>
<div style="width:350px" class="well">

<div  class="control-group">
<span id="errorMessage" class="error">
<s:property value="successErrorForm.errorMessage"></s:property>
</span>
</div>
<div class="control-group">
<span class="span1"><s:text name="label.login.name" /></span>
<s:textfield id="name" name="user.name" cssClass="validate[required]" />
</div>
<div class="control-group">
<span class="span1"><s:text name="label.login.password" /></span>
<s:password id="password" name="user.password" cssClass="validate[required]"/>
</div>
<div class="control-group">
<span class="span1"><s:text name="label.login.language" /></span>
<s:set name="SESSION_LOCALE" value="#session['WW_TRANS_I18N_LOCALE']"/>
<s:bean id="locales" name="com.wizarpos.tms.common.language.LanguageSelectList">
<s:param name="current" value="#SESSION_LOCALE == null ? locale : #SESSION_LOCALE"/>
</s:bean>
<s:select id="languageSelecter" href="login!changeLanguage.action" list="#locales.locales" listKey="value" listValue="key" value="#SESSION_LOCALE == null ? locale : #SESSION_LOCALE" name="request_locale" onchange="languageSelecter_onChanged(this)"/>
</div>
<div class="control-group">
<button type="submit" class="btn btn-primary">
          <s:text name="label.login.login" />
       </button>
<!--         <button type="button" onclick="closeme();" class="btn btn-primary"> -->
<%--            <s:text name="label.login.quit" /> --%>
<!--         </button> -->
</div>
<div class="control-group">
<a href="#" id="modifyPassword" url="authority/user-modify-password!input.action" dialogWidth="500" dialogHeight="400">
          <s:text name="label.login.modifyPassword" />
       </a>
       <a href="#" id="sendPassword" url="authority/user-send-password!input.action" dialogWidth="500" dialogHeight="200">
          <s:text name="label.login.sendPassword" />
       </a>
</div>
</div>
</div>
</form>
</body>
</html>


首先在刷新页面时,htmlTest()对话框显示结果为
aaa
<script src="/tms/static/jquery-Validation-Engine/js/languages/jquery.validationEngine-en_US.js" type="text/javascript"></script>

然后点击语言切换,post返回切换语言后的本页源码alert(html):

<!DOCTYPE html>
<html id="htmlObject">
<head>
<title>123</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta http-equiv="Cache-Control" content="no-store"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/><link href="/tms/static/bootstrap/2.1.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
  相关解决方案