一旦激活了ajax回调函数,我想调用一个内部函数。因为有一个延迟,我想知道我的局部变量在被调用时是否仍然正确,特别是 this.response_element 因为它被回调函数使用。
ajax时发起回调函数status == 200
var ControlSignIn = function( )
{
this.form_element = document.getElementById( 'signin' ),
this.response_element = document.getElementById( 'signin_response' ),
this.text_object = new Text( this.form_element ),
this.message_object = new Message( this.response_element );
};
ControlSignIn.interface = function()
{
new ControlSignIn().invoke();
};
ControlSignIn.prototype.invoke = function( )
{
if( CONSTANT.VALIDATE_ON === 1 )
{
if( !this.text_object.checkEmpty() )
{
this.message_object.display( 'empty' );
return false;
}
if( !this.text_object.checkPattern( 'email' ) )
{
this.message_object.display( 'email' );
return false;
}
if( !this.text_object.checkPattern( 'pass' ) )
{
this.message_object.display( 'pass' );
return false;
}
}
/* new internal call_back */
AjaxNew.use( ajaxSerialize( this.form_element ) + '&ajax_type=ControlSignIn', ControlSignIn.invoke.callBack );
function callBack( server_response_text )
{
ajaxType( server_response_text, this.response_element, 'respond' );
}
/* Removed
Ajax.repeatUse( ajaxSerialize( this.form_element ) + '&ajax_type=ControlSignIn', ajaxTypeRespond, this.response_element );
*/
};
解决方案:
AjaxNew.use( ajaxSerialize( this.form_element ) + '&ajax_type=ControlSignIn', ControlSignIn.invoke.callBack );
var response_element = this.response_element;
function callBack( server_response_text )
{
ajaxType( server_response_text, response_element, 'respond' );
}