2011-03-10 58 views
0

我想创建一个“类似门户”的应用程序与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丢失

回答

0

试想一下,你在你的DOM元素一个当它是负担,你将通过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功能。

+0

这不是答案,从这里删除,并写在评论下面的问题,否则人会downvote你 – diEcho 2011-03-10 04:58:23