我正在寻找一种方法来将 GET Form 结果页面定位到 div。到目前为止,大多数解决方案都告诉我改用 Iframe,但我的目的是对结果页面进行一些更改,并且使用 Iframe 似乎会激活跨域脚本规则,从而阻止我获取页面内容。
结果页面通常是原始 XML。
<html>
<head>
<link rel="stylesheet" href="css/smoothness/jquery-ui-1.9.2.custom.css" >
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery-ui-1.9.2.custom.js"></script>
<script src="js/jquery.xslt.js"></script>
<script type="text/javascript">
$(function() {
var xmlContent = $("#CFrame").contents().find("*").text();
$('#SResult').xslt({xml:xmlContent, xslUrl:'stylesheet/styleSheet.xsl'});
});
// prepare the form when the DOM is ready
function submitForm() {
// bind form using ajaxForm
$('#searchForm').ajaxForm({
// dataType identifies the expected content type of the server response
dataType: 'xml',
// success identifies the function to invoke when the server response
// has been received
success: processXml
});
return false;
}
function processXml(responseXML) {
// 'responseXML' is the XML document returned by the server; we use
// jQuery to extract the content of the message node from the XML doc
var message = $(responseXML).text();
$("#SResult").text(message);
}
</head>
<body>
<form id="searchForm" method="GET" action="http://111.11.111.11:1111/search" onSubmit="submitForm()">
<!--.... Some input go here-->
<input type="submit" value="Search" />
<div id="SResult">
</div>
<iframe id="CFrame" name="ContentFrame" frameborder="1" height="1000px" width="1000px" scrolling="no"></iframe>
</body>
<script>
loadUI();
</script>
</html>
谢谢,