的结果得到了下面的代码:函数返回Ajax调用
$('#next_btn').click(function() {
addUser();
}); //$('#next_btn').click
function addUser() {
var participant = {};
var PID = 0;
PID = FindUserByEmail($('#UserEmail').val());
// do other things and add this user's data to the participant JSON object
} // function addUser()
function FindUserByEmail(user_email) {
var url = escape(AJAX_URL_SELECTBYEMAIL + user_email);
$.ajax({async: true
, type:'POST'
, url: url
, dataType: 'json'
, success: ajax_find_user_result
, error: ajax_error
}); // $.ajax
} // function FindUserByEmail(user_email)
function ajax_error(jqXHR, textStatus, errorThrown) {
alert('X:' + jqXHR.status);
alert('E:' + thrownError);
} // function ajax_error(jqXHR, textStatus, errorThrown)
function ajax_find_user_result(data) {
if(data.result) {
pid = data.result.PID;
if (pid == 0) {
alert('User not found');
return false;
} else {
alert(pid);
} // if (pid == 0)
} else {
alert('No results returned');
return false;
} // if(data.result)
} // function ajax_find_user_result(data)
的ADDUSER()函数是从点击事件被调用。我如何确保函数FindUserByEmail从ajax调用返回值?我不知道如何做到这一点。
通过自己调用URL返回正确的JSON,演示返回正确的PID。只是不知道如何做到这一点,如上所述。