Skip to content
didier Belot edited this page Mar 6, 2018 · 2 revisions

Example

pq('#element')->load('http://somesite.com/page .inline-selector')->...

Table of Contents

Server Side Ajax

Ajax, standing for Asynchronous JavaScript and XML is combination of HTTP Client and XML parser which doesn't lock program's thread (doing request in asynchronous way).

phpQuery also offers such functionality, making use of solid quality Zend_Http_Client. Unfortunately requests aren't asynchronous, but nothing is impossible. For today, instead of XMLHttpRequest you always get Zend_Http_Client instance. API unification is planned.

Cross Domain Ajax

For security reasons, by default phpQuery doesn't allow connections to hosts other than actual $_SERVER['HTTP_HOST']. Developer needs to grant rights to other hosts before making an Ajax request.

There are 2 methods for allowing other hosts

  • phpQuery::ajaxAllowURL($url)
  • phpQuery::ajaxAllowHost($host)
// connect to google.com
phpQuery::ajaxAllowHost('google.com');
phpQuery::get('http://google.com/ig');
// or using same string
$url = 'http://google.com/ig';
phpQuery::ajaxAllowURL($url);
phpQuery::get($url);

Ajax Requests

Ajax Events

  • ajaxComplete($callback) Attach a function to be executed whenever an AJAX request completes. This is an Ajax Event.
  • ajaxError($callback) Attach a function to be executed whenever an AJAX request fails. This is an Ajax Event.
  • ajaxSend($callback) Attach a function to be executed before an AJAX request is sent. This is an Ajax Event.
  • ajaxStart($callback) Attach a function to be executed whenever an AJAX request begins and there is none already active. This is an Ajax Event.
  • ajaxStop($callback) Attach a function to be executed whenever all AJAX requests have ended. This is an Ajax Event.
  • ajaxSuccess($callback) Attach a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event.

Misc

  • phpQuery::ajaxSetup($options) Setup global settings for AJAX requests.
  • serialize() Serializes a set of input elements into a string of data. This will serialize all given elements.
  • serializeArray() Serializes all forms and form elements (like the .serialize() method) but returns a JSON data structure for you to work with.

Options

Detailed options description in available at jQuery Documentation Site.

  • async Boolean
  • beforeSend Function
  • cache Boolean
  • complete Function
  • contentType String
  • data Object, String
  • dataType String
  • error Function
  • global Boolean
  • ifModified Boolean
  • jsonp String
  • password String
  • processData Boolean
  • success Function
  • timeout Number
  • type String
  • url String
  • username String

Read more at Ajax section on jQuery Documentation Site.

Clone this wiki locally