.live(submit) and ajax
.live(submit) and ajax
When I set up a form that includes a file upload requester and do a normal form submit all the form elements are received by the server side PHP script just fine. When I try to apply this snippet below to post the same form elements via AJAX then the actual submit button and file input are missing...
- $("#viewtree form.dialog").live("submit", function() {
- var $form = $(this);
- $.post(
- $form.attr("action"),
- $form.serialize(),
- function(data, status, xhr) {
- $form.closest("dd").html(data);});
- return false;
- });
Even using just .submit() instead of .live(submit) makes no difference, neither does v1.4.2 or v1.3.2. I've seen a suggestion to use live(click) and disable submit with .1.4.2 so this almost works...
- $("#viewtree form").live("submit", function() { return false; });
- $("#viewtree form input.button").live("click", function() {
- var $form = $(this).closest("form");
- var file = $form.find('input[type="file"]')[0];
- var f = $form.serialize() + "&" +$(this).attr("name") + "=" + $(this).attr("value");
- $.post($form.attr("action"), f, function(data) {
- $form.closest("dd").html(data);});
- return false;
- });
But I am still missing any input[type=file] info. Would anyone have a general solution for using .live(submit) in an AJAX context or at least how could I assemble and serialize input[type=file] selector settings when using enctype="multipart/form-data" ?