I need to find out how to access “data” variable outside of the post function. It will return either valid or invalid so I can finish the main function logic.
Is this the right way to do it:
$('#form_choose_methods').submit(function(){
var voucher_code = $('#voucher_code').val();
var check = $.post(baseURL+"ajax.php", { tool: "vouchers", action: "check_voucher", voucher_code: voucher_code },
function(data) {
});
alert(check);
return false;
});
check seems to be the object, but I want to know how to access result of it.
You can access the response in the success callback you use
Ajax calls are asynchronous, so you will only have access to the result from the callback whenever it completes..