简体   繁体   中英

Using netbeans 6.9 to debug ajax/xmlhttprequest and php

I am using netbeans 6.9 and use xdebug to step through my php file which is great. however, I have been using ajax/xmlhttprequest in my project and i have a hard time debugging that. i did some research and came across firebug/firephp and read through a little. i am not against learning new tools but if it can be integrated into the ide i am currently using, it will be more efficient and effective.

so, to provide more example, suppose on my index.php i have this:

<button onclick="getTweet()">Get Tweets!</button>

the getTweet() function reside in a .js file

function getTweet(){
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
             // do something here
        }
    }
    xmlhttp.open("GET", "getTweet.php?q="+$phpVars,true);
    xmlhttp.send();
}

getTweet.php goes out and does a twitter search:

$search = "http://search.twitter.com/search.atom?q=" . $q . "";
$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, $search);
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($tw);
$search_res = new SimpleXMLElement($twi);

Now, i am new to web development, php, js, ajax, html, xml, json, netbeans. I literally am learning all of this in the past 3.5 months so i'm new and need clear instructions.

In getTweet.php, i can insert breakpoints in netbeans BUT...when i click the html button which triggers getTweet() from .js file which makes a xmlhttprequest, the debugger in netbeans does not trigger. Being able to see the variables and its outputs (XML, JSON, etc...) helped me tremendously in learning this stuff so I would like to be ale to see vars in getTweet.php such as $twi,$search_res,etc...

Thanks for the advice!!!

PS: Will firebug work for what I am trying to achieve? I am learning slowly and don't want to pile up too many things at once. Thanks!

In order to get the debugger triggered in getTweet.php , you need to indicate to xdebug that the debugger is listening by sending the XDEBUG_SESSION_START parameter. Update the code in getTweet() to have the following:

xmlhttp.open("GET", "getTweet.php?XDEBUG_SESSION_START=netbeans-xdebug&q="+$phpVars,true);

Xdebug will only catch server-side events, meaning you can't step through your client-side script with it. However, Netbeans does have the ability to step through Javascript (I haven't actually tried it myself as I use Firebug to step through script).

Here's some documentation on setting up script debugging in your Netbeans project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM