-
Notifications
You must be signed in to change notification settings - Fork 66
Ajax
pq('#element')->load('http://somesite.com/page .inline-selector')->...
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.
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);
- phpQuery::ajax($options) Load a remote page using an HTTP request.
- load($url, $data, $callback) Load HTML from a remote file and inject it into the DOM.
- phpQuery::get($url, $data, $callback) Load a remote page using an HTTP GET request.
- phpQuery::getJSON($url, $data, $callback) Load JSON data using an HTTP GET request.
- phpQuery::getScript($url, $callback) Loads, and executes, a local JavaScript file using an HTTP GET request.
- phpQuery::post($url, $data, $callback, $type) Load a remote page using an HTTP POST request.
- 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.
- 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.
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.