我正在尝试使用具有html页面的HeadContainer应用程序(基本上是EAR)创建一个“类似门户”的应用程序。这个html页面里面有2个div。每个div再次是一个EAR - 每个div加载EAR即应用程序。让我们说它们是AppChild1和AppChild2。
我在HeadContainer javascript中使用jQuery加载加载AppChild1和AppChild2。
当我尝试在AppChild1中提交表单时,我正在使用jQuery进行ajax发布。这是AppChild1应用程序中的外部JavaScript文件。假设文件名是scriptFile1.js
Firebug告诉我它试图在HeadContainer的上下文中找到scriptFile1.js,这是不正确的。
当我将鼠标悬停在FireBug中的表单上时,它显示在HeadContainer中 - 它显示AppChild1表单和标题,但是包含的AppChild1脚本文件完全丢失。
有人可以解释这里出了什么问题吗?
好的,因为你们中的一些人想要我给代码结构的代码。
The HeadContainer EAR structure is like this
HeadContainer has a html called Main.html
**Main.html**
----------------
<html>
<head><title>Main Page</title>
<script lanuage="text/javascript">//Include jQuery library </script>
</head>
<body>
<form name="MainForm" id="MainId">
<div name="div1" id="div1"/><br />
<div name="div2" id="div2" /><br />
<input type="submit" id="MainSubmit" />
</form>
</body>
</html>
Main.html has an asscociated javascript file main.js
$(document).ready(function() {
$("#div1").load(div1url,function(){
//load function call back implementation
});//Close load
$("#div2").load(div1url,function(){
//load function call back implementation
}); //Close load
});//doc.ready closing
//AppChild1 is a EAR which is loaded into div1
//AppChild1 has a html div1.html and a associated scriptFile1.js file.
//It is this js file which is not getting loaded
**div1.html** is like this
<html>
<head><title>Div1 Page</title>
<script lanuage="text/javascript">//Include jQuery library </script>
</head>
<body>
<form name="div1Form" id="div1Id">
<input name="txtName1" id="txtname1"/><br />
<div name="txtName2" id="txtName2" /><br />
<input type="submit" id="div1Submit" />
</form>
</body>
</html>
**scriptFile1.js**
$(document).ready(function() {
$("#div1Submit").submit({
$.ajax({
data: $("#div1Form").serialize(),
url : "/someServlet",
success:function(response){
//load the next screen with values from the response object.Response is a
//json object.
}
});
}); //Close Submit
});//doc.ready closing
//The AppChild2 is also on the similar lines
//When I load the Main.html in Firebug - it looks for scriptFile1.js file under the //HeadContainer which is not correct. scriptFile1.js is under AppChild1 EAR. This is //happening at the load of the main page.
//当我查看div1时,如果显示表单和标题但是包含的// javascript文件缺少scriptFile1.js
答案 0 :(得分:0)
想象一下,当你加载DOM时,你的DOM中有一个元素,你将加载一个via ajax并将它附加在'a1'中。
$('#a1').load(my url, function(data){
$(this).html(data);
});
所以我们有这样的事情:
<div id='a2'>
<div id='a2'>
</div>
</div>
在你的'a2'中,你有一些事件,当一个锚点击它将是一个警报。这不起作用:
$('#a2 a').click(function(){
alert('some action');
});
这将:
$('#a2 a').live('click', function(){
alert('some action');
});
在Jquery文档中查看.live函数。