@@ -150,6 +150,16 @@ public function getServerParameter($key, $default = '')
150
150
return isset ($ this ->server [$ key ]) ? $ this ->server [$ key ] : $ default ;
151
151
}
152
152
153
+ public function switchToAjax ()
154
+ {
155
+ $ this ->setServerParameter ('HTTP_X-Requested-With ' , 'XMLHttpRequest ' );
156
+ }
157
+
158
+ public function removeAjax ()
159
+ {
160
+ unset($ this ->server ['HTTP_X-Requested-With ' ]);
161
+ }
162
+
153
163
/**
154
164
* Returns the History instance.
155
165
*
@@ -249,14 +259,15 @@ public function click(Link $link)
249
259
*
250
260
* @param Form $form A Form instance
251
261
* @param array $values An array of form field values
262
+ * @param bool $isAjax Whether it's ajax or not
252
263
*
253
264
* @return Crawler
254
265
*/
255
- public function submit (Form $ form , array $ values = array ())
266
+ public function submit (Form $ form , array $ values = array (), $ isAjax = false )
256
267
{
257
268
$ form ->setValues ($ values );
258
269
259
- return $ this ->request ($ form ->getMethod (), $ form ->getUri (), $ form ->getPhpValues (), $ form ->getPhpFiles ());
270
+ return $ this ->request ($ form ->getMethod (), $ form ->getUri (), $ form ->getPhpValues (), $ form ->getPhpFiles (), array (), null , true , $ isAjax );
260
271
}
261
272
262
273
/**
@@ -269,17 +280,22 @@ public function submit(Form $form, array $values = array())
269
280
* @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
270
281
* @param string $content The raw body data
271
282
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
283
+ * @param bool $isAjax Whether it's a ajax request or not
272
284
*
273
285
* @return Crawler
274
286
*/
275
- public function request ($ method , $ uri , array $ parameters = array (), array $ files = array (), array $ server = array (), $ content = null , $ changeHistory = true )
287
+ public function request ($ method , $ uri , array $ parameters = array (), array $ files = array (), array $ server = array (), $ content = null , $ changeHistory = true , $ isAjax = false )
276
288
{
277
289
if ($ this ->isMainRequest ) {
278
290
$ this ->redirectCount = 0 ;
279
291
} else {
280
292
++$ this ->redirectCount ;
281
293
}
282
294
295
+ if (true === $ isAjax ) {
296
+ $ this ->switchToAjax ();
297
+ }
298
+
283
299
$ uri = $ this ->getAbsoluteUri ($ uri );
284
300
285
301
$ server = array_merge ($ this ->server , $ server );
@@ -324,6 +340,10 @@ public function request($method, $uri, array $parameters = array(), array $files
324
340
$ this ->redirect = null ;
325
341
}
326
342
343
+ if (true === $ isAjax ) {
344
+ $ this ->removeAjax ();
345
+ }
346
+
327
347
if ($ this ->followRedirects && $ this ->redirect ) {
328
348
$ this ->redirects [serialize ($ this ->history ->current ())] = true ;
329
349
@@ -354,7 +374,7 @@ protected function doRequestInProcess($request)
354
374
unlink ($ deprecationsFile );
355
375
foreach ($ deprecations ? unserialize ($ deprecations ) : array () as $ deprecation ) {
356
376
if ($ deprecation [0 ]) {
357
- trigger_error ($ deprecation [1 ], E_USER_DEPRECATED );
377
+ @ trigger_error ($ deprecation [1 ], E_USER_DEPRECATED );
358
378
} else {
359
379
@trigger_error ($ deprecation [1 ], E_USER_DEPRECATED );
360
380
}
0 commit comments