Jump to content

How to use Postman to test AJAX requests


bernhard
 Share

Recommended Posts

This is actually very easy but might be interesting for someone anyhow (and I post it here as a reminder for myself).

You can use Postman (https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=de) to send requests to your ProcessWire installation and test request answers. The problem is that $config->ajax will always return FALSE.

To make the $config->ajax work properly you just need to add this key-value-pair to your requests:

key: X-Requested-With
value: XMLHttpRequest

5ac4d40495439_2018-04-0415_32_20-Postman.png.d77a0357a5d2a5fe72561695e268e08a.png

Happy AJAXing :)

PS: This also works inside the admin, see post 3 :)

  • Like 7
  • Thanks 1
Link to comment
Share on other sites

Thanks for the tip.

btw - PHPStorm has a REST client tool built-in (this is more of a reminder / info for other PHPStorm users - it's such a massive IDE that handy features like these can be easily missed)

  • Like 2
Link to comment
Share on other sites

You can even use it inside the backend:

  • Install Postman Interceptor extension
  • Activate the extension in the browser and in the postman app
  • Go to your desired admin page (eg /page/edit/?id=123)
  • The request will show up in the history and you can modify it to your needs

I'm doing a die('test') here in the admin, with tracy installed, of course O0

5ac4e00dc2a25_2018-04-0416_23_12-Postman.thumb.png.bab5af2662c3d7043fd5fec9f2164923.png

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...