Reputation: 13672
How can I debug a page that receives an Ajax POST request? For a page receiving a GET request, I would simply manually enter the URL, like:
http://localhost/.../myAjaxPage.php?paramName1=paramValue1¶mName2=paramValue2
In this page I would have the var_dumps
or echo
needed to make sure everything works as I want it to.
How can I do that with a page receiving a POST request?
Upvotes: 0
Views: 195
Reputation: 357
If you really need to debug POST responses in your browser, build an HTML form that you can fill and submit manually. The response will be identical whether you're using AJAX or not.
That being said, your web browser often isn't ideal for debugging server-side code, especially when you need to do more than simple GET requests. It's often useful to be able to manually set request headers and see the raw response text from your server, and in these cases you're better off using a different tool. On the Mac, I rather like CocoaRestClient, but there are many similar programs for other platforms (eg Wiztools.org's RESTClient), as well as command-line utilities like curl.
Upvotes: 1
Reputation: 100100
You can use curl
to make POST request from command line.
Chrome developer tools, in the network tab, has "Copy as curl" option when you right-click an XHR request entry. This will give you curl
command that replicates the request with POST, all headers, cookies, etc.
You could of course also inspect response in the inspector itself. If you can't attach debug information to the response, then you can output it in a custom HTTP header (<?php header("X-my-debug: $stuff")
, you'll need to add ob_start()
at beginning of script)
Upvotes: 1