問題は、Parse_Error 関数に対して return ステートメントが返されないことです。これは、JQuery にデータを渡す宣言 ( ) と呼ばれる無名関数に対して返されますがfunction(data){...}、これは事実上無視されます。代わりに、次のようにする必要があります。
// your code that does the query
do_error_query('The Error Message');
function do_error_query(ErrMsg) {
$.post("ajax/errormsg.php", {errmsg: ErrMsg} , function(data){
alert(data);
// here you need to call a function of yours that receives the data.
// executing a return statement will return data to jquery, not to the calling
// code of do_error_query().
your_function(data);
});
}
function your_function(data){
// process the data here
}
do_error_query()問題は、PHP ページからの結果が返される前に呼び出しが完了することです。したがって、結果が返される可能性はありません。つまり、リターンyour_function(data)後によく呼び出されdo_error_query()ます。それが理にかなっていることを願っています。
実質的にdo_error_query()は、イベント ハンドラーをセットアップするだけです。イベントがまだ完了していないため、値を返すことができません。それがイベントハンドラのyour_function(data)目的です。イベントを処理し、PHP ページからデータを返します。イベントはまだ完了していませんが、do_error_query()長い間終了する予定です。