【发布时间】:2015-06-12 11:55:11
【问题描述】:
我在 html 页面上使用 jQuery 将另一个页面加载到 div 中,使用 .ajax()。 第二页有一个表格。当该表单提交时,我想调用一个函数(位于初始页面上)。目前我得到这个“ReferenceError: getHistory is not defined”(其中 'getHistory 是函数的名称)。
MAIN PAGE(减少空间)- 对象:单击按钮,出现表单,提交表单,从 ajax 调用更新历史记录。
<!DOCTYPE html>
<html lang="en" >
<head>...</head>
<body>
<div id="msg"></div>
<input type="button" id="AddEvent" value="add" />
<div id="addForm"></div>
<div id="history"></div>
<!-- script references -->
<script src="js/jquery.min.js" ></script>
<script src="js/bootstrap.min.js" ></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
$( document ).ready( function() {
// Show form
$( '#AddEvent' ).click( function() {
$( '#addForm' ).hide();
$( '#addForm' ).load( 'addform.html', function( response, status, xhr ) {
$( '#addForm' ).slideDown( 1000 ).fadeIn( 3000 );
if ( status == 'error' ) {
var msg = 'Sorry but there was an error loading the form: ';
$( '#msg' ).html( msg + xhr.status + ' ' + xhr.statusText );
}
});
});
// function to populate history
function getHistory() {
...AJAX to populate history div...
}
// initial load on page load
getHistory();
}
</script>
</body>
FORM PAGE:(减少空间)。
<form role="form" id="eventform" action="/eventHandeler" method="post" >
...
</form>
<script>
$( document ).ready( function() {
$( '#eventform' ).ajaxForm( function() {
alert("Thank you for add!");
// ****** THIS IS WHERE I WANT TO RELOAD THE HISTORY...function on parent page
getHistory();
});
});
【问题讨论】:
标签: javascript jquery ajax