3

I am a beginner web developer, specifically, with PHP and some front-end techniques (HTML,CSS,JS/JQuery). I found in some situations, it's quite difficult find the bugs in PHP code. Here is one of examples:

In a HTML page, I use JQuery to submit (with post) a form to a PHP file for back-end transaction. Since I am using JQuery, the page will not be redirected to the PHP page, so if the PHP code has some bugs (even some stupid syntax / SQL errors), it can be hardly to detect them when we test them with a normal navigator.

My question is : if I use echo in the PHP page in the above case, where will the output reside ? I think there should exist some log files for all these sorts of output. What's more, if there are some bugs in the JavaScript, are there any tricks to quickly locate the bugs ?

PS: I am using PHPStorm as IDE under MAC OS.

3
  • what browser are you using? Commented Apr 24, 2013 at 8:53
  • log file will be create by system itself if there is any parser/or fatal error in error_log and use chrome or firefox developer console if you are working with ajax Commented Apr 24, 2013 at 9:00
  • @intelis I principally use either Firefox or Safari. Commented Apr 24, 2013 at 9:01

5 Answers 5

5

When you are running AJAX (it sounds that way judging from your question), all jQuery is doing is request the page 'for you'. So instead that you can directly see the output, jQuery will 'catch' it for you. An AJAX request is nothing more than a normal HTTP request, just in the background so you won't see it.

Therefore; when you 'echo' something, it will just be handled by jQuery and therefore sent to your browser.

There are some tools like firebug that allow you to look into the request and response from your ajax messages, and thus displaying possible errors or different output too. It's an all-around debugger, so you can also see your rendered HTML and/or JavaScript errors.

Sign up to request clarification or add additional context in comments.

4 Comments

it seems now Firefox has built-in web-developper tools which is quite similar to Firebug, although I am not guru for both tools. With the web-developper tools, I can check the request body, but can still difficult to find bugs in the back-end php code.
Firebug is much more useful than the built in dev tools especially for ajax debugging as it allows you to see both your request and the response which will also display any php errors if your code behind page has errors thrown up.
@Dave Yes, I find now I could see the output content. Really nice! :)
@EnsomHodder I don't think the built-in tools are as useful and powerful as firebug.
1

If you are using PHPstorm i suggest you to take a look at Xdebug. You have to enable Xdebug module from your server and you can manage php with breakpoints and varibles Watches.

3 Comments

if you are using mac i suggest you to take a look at [kubyshkin.ru/posts/… for Mac
Yep, I found this tool together with Zend Debugger. I installed them, and checked they are running (with a test phpinfo() page). However, I didn't manage to integrate Xdebug within my PHPStorm.
you can easily menage the debug session with [jetbrains.com/phpstorm/marklets/]. It helped me a lot with services in php.
0

When you are developing the PHP pages, where the ajax is requesting from, make them first to output the result on the screen, test them, then make the jquery request, when you are sure they are outputting the proper thing

Comments

0

use "Firebug" console for firefox, "Firebug lite" for chrome or press "F12" for IE. You will see the console. there you can see the ongoing ajax request and see the response.

Comments

-1

To answer your question specifically; the output from the echo in your example will be in the response to the post request. Normally that would be the page reload but in an ajax request (as you stated) you don't get that.

Use a browser developer tool like the Inspector in chrome or firebug in Firefox to allow you to see the Ajax responses from you post request

You can also log the responses using the console.log Javascript method, in the success section of your ajax

$(function() {

    $.ajax({
        // snip
        success: function(response) {
            console.log(response);
        }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.