Skip to content

Commit d37386c

Browse files
Improved documentation of Ajax methods
See Codeception/Codeception#5977 If you merge this, I'll add the same to [REST module's `sendPOST()`](https://github.com/Codeception/module-rest/blob/master/src/Codeception/Module/REST.php#L446) Questions: * Is the info about `X-Requested-With: XMLHttpRequest` correct? I mean: *How* is the header added when in fact there is no real request, see Codeception/codeception.github.com#334 * Is it possible to add a link in those docblocks? Would be nice for "See `sendAjaxPostRequest()`"
1 parent 7bdcee4 commit d37386c

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/Codeception/Lib/InnerBrowser.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,10 +1254,8 @@ public function attachFile($field, $filename)
12541254
}
12551255

12561256
/**
1257-
* If your page triggers an ajax request, you can perform it manually.
1258-
* This action sends a GET ajax request with specified params.
1259-
*
1260-
* See ->sendAjaxPostRequest for examples.
1257+
* Sends an ajax GET request with the passed parameters.
1258+
* See `sendAjaxPostRequest()`
12611259
*
12621260
* @param $uri
12631261
* @param $params
@@ -1268,42 +1266,40 @@ public function sendAjaxGetRequest($uri, $params = [])
12681266
}
12691267

12701268
/**
1271-
* If your page triggers an ajax request, you can perform it manually.
1272-
* This action sends a POST ajax request with specified params.
1273-
* Additional params can be passed as array.
1274-
*
1269+
* Sends an ajax POST request with the passed parameters.
1270+
* The appropriate HTTP header is added automatically:
1271+
* `X-Requested-With: XMLHttpRequest`
12751272
* Example:
1276-
*
1277-
* Imagine that by clicking checkbox you trigger ajax request which updates user settings.
1278-
* We emulate that click by running this ajax request manually.
1279-
*
12801273
* ``` php
12811274
* <?php
1282-
* $I->sendAjaxPostRequest('/updateSettings', array('notifications' => true)); // POST
1283-
* $I->sendAjaxGetRequest('/updateSettings', array('notifications' => true)); // GET
1284-
*
1275+
* $I->sendAjaxPostRequest('/add-task', ['task' => 'lorem ipsum']);
12851276
* ```
1277+
* Some frameworks (e.g. Symfony) create field names in the form of an "array":
1278+
* `<input type="text" name="form[task]">`
1279+
* In this case you need to pass the fields like this:
1280+
* ``` php
1281+
* <?php
1282+
* $I->sendAjaxPostRequest('/add-task', ['form' => [
1283+
* 'task' => 'lorem ipsum',
1284+
* 'category' => 'miscellaneous',
1285+
* ]]);
1286+
* ```
12861287
*
1287-
* @param $uri
1288-
* @param $params
1288+
* @param string $uri
1289+
* @param array $params
12891290
*/
12901291
public function sendAjaxPostRequest($uri, $params = [])
12911292
{
12921293
$this->sendAjaxRequest('POST', $uri, $params);
12931294
}
12941295

12951296
/**
1296-
* If your page triggers an ajax request, you can perform it manually.
1297-
* This action sends an ajax request with specified method and params.
1298-
*
1297+
* Sends an ajax request, using the passed HTTP method.
1298+
* See `sendAjaxPostRequest()`
12991299
* Example:
1300-
*
1301-
* You need to perform an ajax request specifying the HTTP method.
1302-
*
13031300
* ``` php
13041301
* <?php
1305-
* $I->sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title'));
1306-
*
1302+
* $I->sendAjaxRequest('PUT', '/posts/7', ['title' => 'new title']);
13071303
* ```
13081304
*
13091305
* @param $method

0 commit comments

Comments
 (0)