Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug AJAX (POST) with PhpStorm and Xdebug?

I have configured PhpStorm to debug HTTP GET - but only when I load a page directly.

When I want to debug AJAX, I take the URL which my JS would request and create a PhpStorm configuration to debug it.

Not particularly elegant, is it?

And, of course, I can't do that for POST requests (or can I?).

Ideally, I would like to load my AngularJs app in the browser (Chrome) and be able to breakpoint and debug the backend in PhpStorm.

I googled a lot, and found much that came close, but I can't find the answer :-(

Who can help?


[Update] a few years later, and I am using the excellent and free Postman to test both GET and POST.

like image 736
Mawg says reinstate Monica Avatar asked Jul 09 '16 08:07

Mawg says reinstate Monica


People also ask

How does xdebug remote work?

When Xdebug is running, it will call back to your IDE (like PhpStorm or VS Code) from the server where it's running. Your IDE will sit and listen for that connection on a specific port (typically port 9000 or 9003).


1 Answers

If Xdebug and PHPStorm are configured to debug HTTP GET when loading a page normally, then simply include the GET parameter in the URL of the AJAX request in your Javascript. For example: http://example.com/script.php?XDEBUG_SESSION_START=PHPSTORM

Turn on Debug listening in PHPStorm, send the AJAX request with the new URL, and the debugger should catch it. The POST data you are looking for should appear in $_POST as usual.

like image 82
TheKarateKid Avatar answered Sep 29 '22 12:09

TheKarateKid