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.
vardeclares the variable within its function scope only. So make sure your AJAX call is within that function (or remove thevar– which declares the variable in global scope).mysubjectsounds like submitting form data. Try$('form#myformid').serialize()instead of the data property if you want to submit form data over your AJAX call.