How to debug AJAX service?

I'm trying to debug an AJAX service that is implemented with YII in a mobile web app using jquery and jquery mobile that is all running on a server on my development machine.

I can set breakpoints in the javascript, but as soon as the ajax call is made via the jQuery $.post(), everything just "hangs" -- the breakpoint set on the first line of PHP code is never hit.  I've tried this using Firefox and Chrome as the browsers.

I've set up a debug configuration for remote javascript.

I'm using Apache (on Windows 7) and following is the directory and server mapping:

I use a virtual host called "md" that has its documentroot set to \htdocs\MessageDoc\source.

The "app" is in \htdocs\MessageDoc\source\proto\LocalFiles\index.html.

The ajax "server" is at  \htdocs\MessageDoc\source\index.php.

My Debug configuration is for remote javascript debug.  URL to open is: http://md/proto/LocalFiles/index.html.  And, I've mapped \htdocs\MessageDoc\source to http://md.

Here are my xdebug settings in php.ini:

zend_extension = "C:\Program Files (x86)\PHP\ext\php_xdebug-2.2.1-5.4-vc9.dll"

xdebug.collect_return=1

xdebug.remote_enable=on

xdebug.remote_handler=dbgp

xdebug.remote_host=localhost

xdebug.remote_connect_back=1

xdebug.remote_port=9000

xdebug.remote_autostart=1


Please help.

17 comments
Comment actions Permalink

Hi Mitch,

Are you trying to debug JavaScript and PHP at the same time? If so -- it is not currently supported -- you can debug only one of them at the same moment in time in convenient way. Please check this ticket http://youtrack.jetbrains.com/issue/WI-676 (unless I misunderstood the issue completely)

0
Comment actions Permalink

I read the note in the link you provided, but I don't know how to start 2 sessions.

Could you please give me some more specific instructions?

I want to be able to set breakpoints in the javascript in the client app and also set breakpoints in the PHP of the ajax server.

Thanks,

Mitch

0
Comment actions Permalink

Sorry, no real idea -- never had the need to do this myself and therefore cannot help here. I would suggest asking for clarification in the actual ticket.

BTW:

  1. Are you able to debug PHP file at all?
  2. Is it working if you debug some very basic simple script? Maybe your php part of debugger is simply not configured?
  3. Please describe how are you trying to debug PHP file. Have a look at this article if you have not seen it yet: http://confluence.jetbrains.net/display/WI/Zero-Configuration+debugging+with+PhpStorm+2.0
0
Comment actions Permalink

Well, the prerequisite is:
1) Make sure you have everything configured properly and can debug your PHP code.
2) Make sure you have everything configured properly and can debug your JS code.

0
Comment actions Permalink

Yes.  I'm able to debug PHP no problem.  I have another site, locally hosted (same thing), that's a Drupal site and I can do a PHP Web Application debug, set breakpoints, etc... no problem.

0
Comment actions Permalink

Yes... I can debug javascript and I can debug PHP -- in separate projects.  I haven't had any problems.  So each is apparently set up fine independently.

This is the first time I'm trying to debug a json service -- which means I have to be able to see what's happening on both sides.

The HTML/javascript is on the same virtual server as the PHP/ajax service.

The HTML/javascript (client) is at http://md/proto/LocalFiles/index.html (plus sub directories where the .js, .css and image files are).

The ajax services are provided by code that's in the yii framework.  It's at http://md/ajax/<whatever-ajax-service-controller-options>

0
Comment actions Permalink

Well, the first thing that comes to my mind - open these projects in two frames, enable php debugging of backend project and then start debugging the frontend.

0
Comment actions Permalink

I'm still pretty new to phpstorm.  Can you point me to some good documentation on frames?  I'm not finding anything useful on how to use frames on my own.

Thanks,

Mitch

0
Comment actions Permalink

Just try to (re)open a project when you have one opened - there should be a prompt: replace current, open in new frame, cancel.

0
Comment actions Permalink

I'm having similar problems in WebStorm with my ruby server. The outbound command is sent in my case but the response from the server is never received when running in the debugger even though it is received when I run in the browser by itself. See WI-13423.

0
Comment actions Permalink

Mitch, I am having exactly the same problem.   I suspect that it is not supported, however I am just checking to see if you managed to find a workaroundt.

0
Comment actions Permalink

I gave up on this.

I pretty much always use Chrome's developer tools to do my javascript debugging now. PHPStorm is fine for basic javascript debugging, just too many bugs for serious work with lots of complex scripts.  As far as the PHP side, I haven't been doing as much on that lately, so PHPStorm has been ok for me there.

0
Comment actions Permalink

"too many bugs for serious work with lots of complex scripts" — Could you prove this statement? Yes, firefox debugger works incorrectly for anonymous functions, but what about debugging in Google Chrome? Could you provide me links to opened issues?

Mitch Perlitch, if you cannot debug JS in case of "AJAX service that is implemented with YII in a mobile web app using jquery and jquery mobile", please open issue and attach test project.

0
Comment actions Permalink

I've posted many bugs.  I don't believe that any have been fixed yet.  It was starting to take too much of my time to deal with the bug reporting.

So, as I said in my note, I've stopped using the javascript debugger in PhpStorm and now use google's developer tools because it is reliable.

I'm sorry, but that is the case.  Someone asked and so I told him what I do.

PhpStorm has lots of potential.  It is just not reliable.

The debugger stops on arbitrary lines at different times, the IDE doesn't correctly parse strings at times, I can't change a variable's value in the debugger, sometimes the editor does code completion when entering text inside of a string (with quotes)....  These are just some of the bugs I've reported. the list goes on and on.

This morning, I decided to try the PhpStorm javascript debugger again.

One click was all it took to find a problem:  http://youtrack.jetbrains.com/issue/WI-16673  I took the time to post the issue.

Maybe you'll be able to fix it?

0
Comment actions Permalink

Hi, it is a rather simple test.

You have a javascript file.  On a user click you wish to load some text using an Ajax call. , e.g.

JavaScript Snippet

$("#loadtextBox")
     .load("lib/buildTextBox.php", {fileName : chosenfileName , async : false}, function() {

The PHP 'buildTextBox.php' file looks like this

<?php

    $fileName = $_SERVER["DOCUMENT_ROOT"].'/'.$_POST["fileName "].'/textList.html';
   header('Content-Description: File Transfer');
    header('Content-Type: text/html');
   header('Expires: 0');
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
     header('Content-Length: ' . filesize($fileName));
    ob_clean();
  flush();
  set_time_limit(20); //Set the execution time to 20 seconds.
  readfile($fileName ); //readfile will stream the file.
?>


You are able to debug the java script file (it works, but appears very crude), however if you set a breakpoint in the php file it is never invoked.   The code works but you cannot debug it.
 

0
Comment actions Permalink

Hi Alex,

Maybe you are doing something wrong e.g. launching JavaScript debugger configuration instead of PHP one?

I have run few tests, and it worked fine on simple examples on my setup -- see this thread for details and code samples: http://devnet.jetbrains.com/thread/441766?tstart=0

Could you please provide your not-working STANDALONE example (must include everything that required to run it -- just as in those examples above)?

0
Comment actions Permalink

Hi Andriy,
              Thanks - I managed to get it to work.   It was indeed a configuration issue!.  The problem I had was that I was not passing the "ide key" back to the local server.


Alex

0

Please sign in to leave a comment.