02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 8-6. After you edit an event, its title is duplicated<br />

CHAPTER 8 ■ EDITING THE CALENDAR WITH AJAX AND JQUERY<br />

To avoid this, you need to add an additional tweak to the form submission click h<strong>and</strong>ler. Because<br />

events being edited will have their ID loaded in the editing form’s hidden input named event_id, you<br />

can check for a length in the input’s value. If the length is not zero, don’t call fx.addevent().<br />

Insert the following bold code to make this check:<br />

// Edits events without reloading<br />

$(".edit-form input[type=submit]").live("click", function(event){<br />

// Prevents the default form action from executing<br />

event.preventDefault();<br />

// Serializes the form data for use with $.ajax()<br />

var formData = $(this).parents("form").serialize();<br />

// Sends the data to the processing file<br />

$.ajax({<br />

type: "POST",<br />

297

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

Saved successfully!

Ooh no, something went wrong!