Best Debug Tool to Debug Ajax Request in PHP

Best debug tool to debug Ajax request in PHP

The simple way is view the trigger in browser itself.

Open the website in chrome browser

  • Click F12.

  • Click on Network tab. Reload the page to find all the files
    getting loaded.

  • select the MyFile.php and then click on the response tab to see ur respone.

You can also see other details like time taken for response, initiator file etc. by this method.

What's the best way to debug AJAX to PHP calls?

FirePHP:

FirePHP enables you to log to your
Firebug Console using a simple PHP
method call.

All data is sent via response headers
and will not interfere with the
content on your page.

FirePHP is ideally suited for AJAX
development where clean JSON and XML
responses are required.

Here is a minimalistic implementation I wrote:

function FirePHP($message, $label = null, $type = 'LOG')
{
static $i = 0;

if (headers_sent() === false)
{
$type = (in_array($type, array('LOG', 'INFO', 'WARN', 'ERROR')) === false) ? 'LOG' : $type;

if (($_SERVER['HTTP_HOST'] == 'localhost') && (strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP') !== false))
{
$message = json_encode(array(array('Type' => $type, 'Label' => $label), $message));

if ($i == 0)
{
header('X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
header('X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
header('X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
}

header('X-Wf-1-1-1-' . ++$i . ': ' . strlen($message) . '|' . $message . '|');
}
}
}

I wrote it so that it only works on localhost (for security reasons), but you can easily change that by replacing the following code:

if (($_SERVER['HTTP_HOST'] == 'localhost') && (strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP') !== false))

With:

if (strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP') !== false)

how to debug php during jquery ajax call

I figured out how to debug it. In the chrome debugger, select the Network tab, then select "screen_custom.php" from the list, then select the Response tab. It shows the output from the php. I uncommented the echo sql statement and could see that in fact, the form parameters are not being read, as I suspected.

Then I googled on that problem and found the solution was to modify the data paramenter js as shown below:

        data: function(d) {
var form_data = $('#criteriaForm').serializeArray();
$.each(form_data, function(key,val) {
d[val.name] = val.value;
});
},

I don't know why the first method didn't work as I could see the correct parameters being sent in the header. But this works.

PHP Tools for Visual Studio. How to debug AJAX requests?

I've found the solution on the DEVSENSE forum
In this case xdebug just doesn't know when it should start debugging. Easist way is to add to php.ini next line:

xdebug.remote_autostart = on

And all works!

How do I debug jquery AJAX calls?

Make your JQuery call more robust by adding success and error callbacks like this:

 $('#ChangePermission').click(function() {
$.ajax({
url: 'change_permission.php',
type: 'POST',
data: {
'user': document.GetElementById("user").value,
'perm': document.GetElementById("perm").value
},
success: function(result) { //we got the response
alert('Successfully called');
},
error: function(jqxhr, status, exception) {
alert('Exception:', exception);
}
})
})

How to Trace Ajax Call Back or Debug Ajax Requests in Chrome or any other Good and Famous Browser

You can use the google chrome devTools console and go to the Network menu. It works great.

If you want more you can use Charles

How to debug ajax response?

After a much needed 10 hour break into the night, I solved the issue with a much clearer mind. I removed the dataType row and it worked for me.

As silly as it may sound, the table in the PHP page was not in JSON format, so when jQuery tries to parse it as such, it fails.

Hope it helps for you. If not, check out more suggestions here.

Before

  $.ajax({
type: 'POST',
dataType : 'json',
url: 'queries/getsocial.php',
data:nvalues,
success: function(response)
{

console.log(response);//does not print in the console
}

});

After (Works now)

  $.ajax({
type: 'POST',
url: 'queries/getsocial.php',
data:nvalues,
success: function(response)
{

console.log(response);//yes prints in the console
}

});


Related Topics



Leave a reply



Submit