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.

80<br />

CHAPTER 2 ■ COMMON JQUERY ACTIONS AND METHODS<br />

Figure 2-22. The loaded AJAX information from ajax.php<br />

$.ajaxSetup()<br />

To set default options for AJAX calls, the $.ajaxSetup() function is used. For instance, to specify that, <strong>by</strong><br />

default, all AJAX requests should be sent to ajax.php using POST <strong>and</strong> then loaded into the paragraph with<br />

ID bar, the following would be used:<br />

$.ajaxSetup({<br />

"type":"POST",<br />

"url":"ajax.php",<br />

"success":function(data){<br />

$("#bar")<br />

.css("background","yellow")<br />

.html(data);<br />

}<br />

});<br />

Now, new AJAX requests can be made easily <strong>by</strong> simply passing new data:<br />

$.ajax({<br />

"data":{<br />

"newvar1":"value1",<br />

"newvar2":"value2"<br />

}<br />

});

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

Saved successfully!

Ooh no, something went wrong!