09.02.2015 Views

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Form Plug-In<br />

$(document).ready(function() {<br />

$('#test-form').ajaxForm({<br />

target: '.ajax-form .log',<br />

beforeSubmit: function(formData, $form, options) {<br />

if ($form.find('#city').val() == '') {<br />

alert('You must enter a city.');<br />

return false;<br />

}<br />

}<br />

});<br />

});<br />

If a validation routine detects errors that the user must correct, the routine can return<br />

false to prevent the form from being submitted. In our example here, a value must<br />

be entered in the City field, or an alert will be shown and no submission will occur.<br />

When a dataType is provided, the response data is interpreted accordingly. The<br />

processing performed is the same as with the $.ajax function, for the supported<br />

data types. Any script responses are interpreted as JavaScript and executed in the<br />

global context, while json responses are parsed as a JavaScript object or array. Calls<br />

that specify an xml data type do not cause any parsing to occur when the response<br />

is received.<br />

If no dataType is provided, then we can instead use the target option. The <strong>DOM</strong><br />

element referred to by the target will be filled with the response to the AJAX<br />

request, interpreted as plain HTML. The dataType and target options are<br />

mutually exclusive.<br />

After any relevant processing has been performed due to the dataType or target<br />

options, the success callback is executed. This function is given the response data to<br />

act on. For information on ways to interpret and manipulate the response data, see<br />

the $.ajax function discussion in Chapter 7.<br />

The semantic flag forces strict semantic ordering at the expense of execution speed.<br />

For more information, see the .formToArray() discussion later.<br />

If resetForm or clearForm is set to true, the corresponding action will be taken<br />

before the success callback (if provided) is executed. For more information on these<br />

actions, see the .clearForm and .resetForm method discussions later.<br />

If the form being submitted contains file upload fields, the file data will be properly<br />

uploaded using the multipart/form-data MIME type. No further action needs to<br />

be taken.<br />

[ 222 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!