我想創建一個「類似門戶」的應用程序與HeadContainer應用程序(基本上是EAR)有一個HTML頁面。這個HTML頁面有2個div。每個div再次是一個EAR - 每個div加載該EAR即應用程序。假設他們是AppChild1和AppChild2。jQuery和div加載
我在HeadContainer JavaScript的使用jQuery負荷加載AppChild1和AppChild2。
當我嘗試在AppChild1提交表單我做使用jQuery AJAX的一個崗位。這是AppChild1應用程序中的外部JavaScript文件。比方說,文件名是scriptFile1.js
螢火蟲讓我發現,它試圖找到HeadContainer的CONTEX這是不對的下scriptFile1.js。
當我將鼠標懸停在Firebug的形式中HeadContainer - 它顯示AppChild1形式和標題,但AppChild1所包含的腳本文件是完全丟失。
有人可以解釋怎麼回事錯在這裏?
OK,因爲幾個你想要的代碼,我會給出代碼結構。
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.
//當我viewsource的DIV1如果顯示窗體和標題,但包括// JavaScript文件scriptFile1.js丟失
這不是答案,從這裏刪除,並寫在評論下面的問題,否則人會downvote你 – diEcho 2011-03-10 04:58:23