I have a simple form that I wish to postback to the server in an easy fashion and get the result. I am using a custom ISAPI plugin on the backend so using JSON or other funky stuff isn't an option. How best can I do this?
Edit: I would also rather not use external plugins, if possible
Use serialize
to get a string representation of your form and then simply post it using jQuery's post
AJAX function.
Very simple example (from jQuery's website using PHP, but any URL would do):
$.post("test.php", $("#testform").serialize());
If you have multiple forms on the page you can use this code on button click to get the correct form Id (where 'someButton' can be any valid jQuery selector):
$('someButton').click(function() {
//old, less efficient code
//var formId = $(this).closest("form").attr("id");
//$.post("test.php", $("#" + formId).serialize());
//as per Vincent Robert's suggestion, simplified version
$.post("test.php", $(this).closest("form").serialize());
});
Another way to do the same thing as Marek commented.
$.ajax({
type: 'POST',
url: YOUR_URL,
data: $('#YOURFORM').serialize(),
success: function(data) {
//Probably should do something that shows it worked.
}
error: function (xhr, ajaxOptions, thrownError){
//Log the error if there was one
}
});