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

Create successful ePaper yourself

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

Edits events without reloading<br />

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

});<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 />

url: processFile,<br />

data: formData,<br />

success: function(data) {<br />

// Fades out the modal window<br />

fx.boxout();<br />

// Adds the event to the calendar<br />

fx.addevent(data, formData);<br />

},<br />

error: function(msg) {<br />

alert(msg);<br />

}<br />

});<br />

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

Save this file <strong>and</strong> reload http://localhost/. Bring up the event creation form <strong>and</strong> create a new event<br />

with the following information:<br />

• Event Title: Addition Test<br />

• Event Start: 2010-01-09 12:00:00<br />

• Event End: 2010-01-09 14:00:00<br />

• Event Description: This is a test of the dynamic addition of new events to the<br />

calendar.<br />

Submitting the form causes the modal window to fade out; a second later, the new event title will<br />

fade in on the calendar in the proper place (see Figure 8-2).<br />

285

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

Saved successfully!

Ooh no, something went wrong!