1 views_ajax.test | public ViewsAjaxTest::simpleAjaxPost($path, $accept, $post = array()) |
Perform a simple AJAX POST HTTP request.
Parameters
string $path: Backdrop path where the request should be POSTed.
string $accept: The value for the "Accept" header. Usually either 'application/json' or 'application/vnd.backdrop-ajax'.
array $post: The POST data. When making a 'application/vnd.backdrop-ajax' request, the Ajax page state data should be included. Use getAjaxPageStatePostData() for that.
Return value
The content returned from the call to curl_exec().:
File
- core/
modules/ views/ tests/ views_ajax.test, line 41 - Definition of ViewsAjaxTest.
Class
- ViewsAjaxTest
- Tests views ajax display.
Code
public function simpleAjaxPost($path, $accept, $post = array()) {
$options['absolute'] = TRUE;
foreach ($post as $key => $value) {
// Encode according to application/x-www-form-urlencoded
// Both names and values needs to be urlencoded, according to
// http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
$post[$key] = urlencode($key) . '=' . urlencode($value);
}
$postfields = implode('&', $post);
$headers = array(
'Accept: ' . $accept,
'Content-Type: application/x-www-form-urlencoded',
);
return $this->curlExec(array(
CURLOPT_URL => url($path, $options),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HTTPHEADER => $headers,
));
}