NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Pointers for debugging Ajax code...


Joined: 03 Jan 2008
Posts: 15
Reply with quote
Hi guys,

I'm using PHPEd to debug an application that uses Ajax. I load the page fine, I make the call fine, I stop at the breakpoint in the Server side file that Ajax called just fine.

However... The file executes perfectly... then exits... but never returns to the browser any results!!

This Ajax app is editing a database, and when I check the database, the changes are getting saved, so that's not a problem... It just doesn't return execution to the browser.

Anybody else have this problem?

Thanks.
View user's profileFind all posts by JudoDanSend private messageAIM Address
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
Quote:
It just doesn't return execution to the browser.

Browser does not execute php and I'm not sure how would debugger return execution to it. Please check your javascript. Probably a kind of timeout triggers there and browser gets execution before the results are provided by the php.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Jan 2008
Posts: 15
Reply with quote
dmitri wrote:
Quote:
It just doesn't return execution to the browser.

Browser does not execute php and I'm not sure how would debugger return execution to it. Please check your javascript. Probably a kind of timeout triggers there and browser gets execution before the results are provided by the php.


Yes, I am aware that PHP is not executed in the browser. I meant that it's not returning the results of the script to the browser I'm not getting anything returned.

(Note that while not debugging, it seems to be working fine...)
View user's profileFind all posts by JudoDanSend private messageAIM Address
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
If you start debuging your php script via an ajax call, it should return the result to the browser. You may want to add an alert to see the returned data.

Quote:
while not debugging, it seems to be working fine...)

again, if script is executed through the ajax call, it will return data the same way regardless you run it with debugger or not. The only difference is time. When you debug your script and execute line by line, it runs much slower so the client may timeout. In this case the added alert will trigger much sooner than you finish your scipt in the debugger.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Jan 2008
Posts: 15
Reply with quote
dmitri wrote:
If you start debuging your php script via an ajax call, it should return the result to the browser. You may want to add an alert to see the returned data.

Quote:
while not debugging, it seems to be working fine...)

again, if script is executed through the ajax call, it will return data the same way regardless you run it with debugger or not. The only difference is time. When you debug your script and execute line by line, it runs much slower so the client may timeout. In this case the added alert will trigger much sooner than you finish your scipt in the debugger.


The alert was not getting displayed. The problem is... some requests have the problem and some do not (which leads me to believe it's in my code...).

I finally narrowed it down. The calls that are failing are post events where I send XML in the Request body. If I comment out the following line:

$body = @file_get_contents('php://input');


it returns no problem (Of course, I can't get my data from the request, but it does return...)

Have you seen this? (Or am I getting the request data the wrong way?)

Thanks.
View user's profileFind all posts by JudoDanSend private messageAIM Address
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
Quote:
The alert was not getting displayed

so the browser kept waiting.

Quote:
If I comment out the following line:

$body = @file_get_contents('php://input');

I'd say, it's quite a strange way of handling posts. If it is HTTP POST you're sending your XML request with, you may want to read your data in $_POST[] array or $HTTP_RAW_POST_DATA
To send the results back to the browser, you need to echo() or print() your data.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Jan 2008
Posts: 15
Reply with quote
dmitri wrote:
Quote:
The alert was not getting displayed

so the browser kept waiting.

Quote:
If I comment out the following line:

$body = @file_get_contents('php://input');

I'd say, it's quite a strange way of handling posts. If it is HTTP POST you're sending your XML request with, you may want to read your data in $_POST[] array or $HTTP_RAW_POST_DATA
To send the results back to the browser, you need to echo() or print() your data.


Well that seems to work. Your expertise is much appreciated! Very Happy

Not that it matters, but why do you say that's a strange way to handle a post? Because I learned that in an AJAX book long ago and I've always done that.

Again, thanks!
View user's profileFind all posts by JudoDanSend private messageAIM Address
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
Quote:
but why do you say that's a strange way to handle a post?

It's strange for anything other than CGI. Only CGI scripts read their POST in the input. In most cases php is not used as CGI and even in this case it would read the input for you and place the results into the arrays I mentioned before your scripts got executed.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Jan 2008
Posts: 15
Reply with quote
dmitri wrote:
Quote:
but why do you say that's a strange way to handle a post?

It's strange for anything other than CGI. Only CGI scripts read their POST in the input. In most cases php is not used as CGI and even in this case it would read the input for you and place the results into the arrays I mentioned before your scripts got executed.


Understood. Again, thanks!
View user's profileFind all posts by JudoDanSend private messageAIM Address
Pointers for debugging Ajax code...
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic