I am building data for an ajax call. I am using jquery.
my function(simplified) is below.
I would like to use the jquery serialize() on vname and vemail, but it seems like you can only do this on form vars. is there a way to do this with normal vars or do i need to do something else to make these vars safe for the ajax call?
Thanks
function sendEmailNotify(vname, vemail, docID){
$.ajax({
type: "POST",
url: "/servlet/trainingServlet",
data: ({method: 'ajaxEmailNotify',vname: vname , vemail: vemail }),
dataType: 'json',
success: function(data){
if ( data.success != "OK" ){
alert(data.message);
}
}
});
}
The jQuery
.serialize()function can be called on a jQuery object that contains one or more forms, or a jQuery object that contains a specific set of individual form input elements, and will return a URL parameter string with all of those values.If
vnameandvemailin your code refer to input elements, then you can create a jQuery object containing those, then call.serialize(). If, however, they are simply values, then you don’t need to do anything else with them.As a semi-related note, you don’t need the parentheses around the object you’re passing to the
dataproperty – I have no idea if having that will cause problems, but since they serve no purpose in being there you may as well remove them.