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.

});<br />

// Prevents the form from submitting<br />

event.preventDefault();<br />

// Sets the action for the form submission<br />

var action = $(event.target).attr("name") || "edit_event",<br />

// Saves the value of the event_id input<br />

id = $(event.target)<br />

.siblings("input[name=event_id]")<br />

.val();<br />

// Creates an additional param for the ID if set<br />

id = ( id!=undefined ) ? "&event_id="+id : "";<br />

// Loads the editing form <strong>and</strong> displays it<br />

$.ajax({<br />

type: "POST",<br />

url: processFile,<br />

data: "action="+action+id,<br />

success: function(data){<br />

// Hides the form<br />

var form = $(data).hide(),<br />

// Make sure the modal window exists<br />

modal = fx.initModal()<br />

.children(":not(.modal-close-btn)")<br />

.remove()<br />

.end();<br />

// Call the boxin function to create<br />

// the modal overlay <strong>and</strong> fade it in<br />

fx.boxin(null, modal);<br />

// Load the form into the window,<br />

// fades in the content, <strong>and</strong> adds<br />

// a class to the form<br />

form<br />

.appendTo(modal)<br />

.addClass("edit-form")<br />

.fadeIn("slow");<br />

},<br />

error: function(msg){<br />

alert(msg);<br />

}<br />

});<br />

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

After saving this file <strong>and</strong> reloading http://localhost/ in your browser, click the New Year's Day<br />

event title to bring up the event description. Inside the modal window, click the Edit This Event button;<br />

295

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

Saved successfully!

Ooh no, something went wrong!