开发者

How to debug AJAX requests? How to know which PHP function is invoked?

I'm debugging Ajax calls.

How do I know which specific PHP function is called by an ajax call ?

I can only see the request and the javascript code triggering the request, but I dunno how is handled on the request on server side ?

I'm currently inspecting all php code, but I was wondering if there is an easier way..

t开发者_StackOverflow社区hanks


An Ajax call does not call a specific function, it merely executes a script. Look at the script, search for its "main" (Whatever name it has in your script) and you'll have the exectued function.


If you want a real debug environment and be able to set breakpoints in your php-code, refer to the zend debugger or xdebug. Both can be controlled with the pdt eclipse-plugin or other IDEs.

If you just want to see some small pieces of information, you can of course just add some echo's or var_dump's to your php-code and then use the firebug firefox extension to view the response to your ajax-requests, which contains the echoed strings.


I would recommend you make use of FireBug and FirePHP. FirePHP allows you to log from PHP to FireBug console. In this way you can log anything for example all the queries being run or log from methods/functions.


Just use firebug and after the request is sent, look for the response. e.g. function1 echo foo, function2 echo bar, if it's blank...none of those 2 function was called.

On my end, I'm using Safari and finding both request / response from an ajax call to a PHP script is a breeze.


Debugging using Firefox's addon FireBug, you can check out the request and response data content easily.

http://www.daniweb.com/web-development/php/code/216729

So by right, Ajax cannot access remote web server content, so you need the proxy page in the middle of the whole architecture flow.

So which means: [Within Same Server] PHP page using AJAX -> Web Services / Web Server that contains your response functions

[Within 2 Servers, Connecting to Remote Server] PHP page using AJAX -> PHP Proxy Page -> Web Services / Web Server that contains your response functions

So the overall proxy page acting like a "middle-man" to connect to remote site.

[IMPORTANT] Don't confuse router proxy and proxy page, but have the same theory but it is different thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜