I' am trying to make a simple reusable ajax function. After spending hours on Google and and trying myself I have no option but to ask for help.
I' am getting "undefined" alert from the Javascript. It works fine when I don't use the function method. Below is the code for it...
$("#formloginadmin").submit(function (){
var url = "ajax/ajax_login_admin.php";
var txtemail = $("#txtemail").val();
var txtpass = $("#txtpass").val();
var formdata = $('#formloginadmin').serialize();
var revel = true;
txtemail = $.trim(txtemail);
txtpass = $.trim(txtpass);
response = ajax_post(url, formdata);
alert(response);
return false;
});
function ajax_post(url, formdata){
$.post(url, formdata, function (data){
return data;
});
}