@@ -1254,10 +1254,8 @@ public function attachFile($field, $filename)
1254
1254
}
1255
1255
1256
1256
/**
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()`
1261
1259
*
1262
1260
* @param $uri
1263
1261
* @param $params
@@ -1268,42 +1266,40 @@ public function sendAjaxGetRequest($uri, $params = [])
1268
1266
}
1269
1267
1270
1268
/**
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`
1275
1272
* 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
- *
1280
1273
* ``` php
1281
1274
* <?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']);
1285
1276
* ```
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
+ * ```
1286
1287
*
1287
- * @param $uri
1288
- * @param $params
1288
+ * @param string $uri
1289
+ * @param array $params
1289
1290
*/
1290
1291
public function sendAjaxPostRequest ($ uri , $ params = [])
1291
1292
{
1292
1293
$ this ->sendAjaxRequest ('POST ' , $ uri , $ params );
1293
1294
}
1294
1295
1295
1296
/**
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()`
1299
1299
* Example:
1300
- *
1301
- * You need to perform an ajax request specifying the HTTP method.
1302
- *
1303
1300
* ``` php
1304
1301
* <?php
1305
- * $I->sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title'));
1306
- *
1302
+ * $I->sendAjaxRequest('PUT', '/posts/7', ['title' => 'new title']);
1307
1303
* ```
1308
1304
*
1309
1305
* @param $method
0 commit comments