My code is;
$.ajax({
type: "POST",
url: "mailyaz.php",
data: {
name: "testest"
}
});
This works with simple "testest" message. But I need to post my javascript variable (var mysubject = blabla). If I replace "testest" with mysubject, its not working.
var
declares the variable within its function scope only. So make sure your AJAX call is within that function (or remove the var
- which declares the variable in global scope).
mysubject
sounds like submitting form data. Try $('form#myformid').serialize()
instead of the data property if you want to submit form data over your AJAX call.