@@ -150,6 +150,16 @@ public function getServerParameter($key, $default = '')
150150return isset ($ this ->server [$ key ]) ?$ this ->server [$ key ] :$ default ;
151151 }
152152
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+
153163/**
154164 * Returns the History instance.
155165 *
@@ -249,14 +259,15 @@ public function click(Link $link)
249259 *
250260 * @param Form $form A Form instance
251261 * @param array $values An array of form field values
262+ * @param bool $isAjax Whether it's ajax or not
252263 *
253264 * @return Crawler
254265 */
255- public function submit (Form $ form ,array $ values =array ())
266+ public function submit (Form $ form ,array $ values =array (), $ isAjax = false )
256267 {
257268$ form ->setValues ($ values );
258269
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 );
260271 }
261272
262273/**
@@ -269,17 +280,21 @@ public function submit(Form $form, array $values = array())
269280 * @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
270281 * @param string $content The raw body data
271282 * @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
272- *
283+ * @param bool $isAjax Whether it's a ajax request or not
273284 * @return Crawler
274285 */
275- public function request ($ method ,$ uri ,array $ parameters =array (),array $ files =array (),array $ server =array (),$ content =null ,$ changeHistory =true )
286+ public function request ($ method ,$ uri ,array $ parameters =array (),array $ files =array (),array $ server =array (),$ content =null ,$ changeHistory =true , $ isAjax = false )
276287 {
277288if ($ this ->isMainRequest ) {
278289$ this ->redirectCount =0 ;
279290 }else {
280291 ++$ this ->redirectCount ;
281292 }
282293
294+ if (true ===$ isAjax ) {
295+ $ this ->switchToAjax ();
296+ }
297+
283298$ uri =$ this ->getAbsoluteUri ($ uri );
284299
285300$ server =array_merge ($ this ->server ,$ server );
@@ -324,6 +339,10 @@ public function request($method, $uri, array $parameters = array(), array $files
324339$ this ->redirect =null ;
325340 }
326341
342+ if (true ===$ isAjax ) {
343+ $ this ->removeAjax ();
344+ }
345+
327346if ($ this ->followRedirects &&$ this ->redirect ) {
328347$ this ->redirects [serialize ($ this ->history ->current ())] =true ;
329348