Jump to content

[SOLVED] AJAX Oddity


aureolin

Recommended Posts

I'm submitting an AJAX request to my server (I'm running a WAMP stack). I can see the server process the request in XDebug and set the return string (an HTML <form>...</form>) correctly. Here's the kicker - when I look at the the responseText from the Ajax request in Firebug, it's not the data that was sent, it's a copy of the entire web page! At the moment I'm stumped. For one, this AJAX request is kicked off as the result of a previously successful AJAX request (a login), but that one works perfectly??

 

Any idea where to look?

 

Steve G.

Link to comment
https://forums.phpfreaks.com/topic/88295-solved-ajax-oddity/
Share on other sites

I'm submitting an AJAX request to my server (I'm running a WAMP stack). I can see the server process the request in XDebug and set the return string (an HTML <form>...</form>) correctly. Here's the kicker - when I look at the the responseText from the Ajax request in Firebug, it's not the data that was sent, it's a copy of the entire web page! At the moment I'm stumped. For one, this AJAX request is kicked off as the result of a previously successful AJAX request (a login), but that one works perfectly??

 

Any idea where to look?

 

Steve G.

 

Are you using some template like smarty???

Link to comment
https://forums.phpfreaks.com/topic/88295-solved-ajax-oddity/#findComment-451989
Share on other sites

Found the answer, and in a surprising place. First, to recap: The problem is that an AJAX call is returning not the form I requested, but the entire web page.

 

Some details on the situation:

  • I'm using a WAMP stack; WinXP, Apache 2.2, PHP 5.2 (i.e. latest stable builds).
  • I'm not using any templates (eg. Smarty); this is just your basic AJAX call.
  • I've tried using the Prototype and jx libraries as well as hand written XMLHttpRequest object code.
  • The problem happens in both Firefox and IE.
  • I can walk through the server code w/ XDEBUG and see the AJAX response being generated correctly.
  • I can walk through the client code and see that the XMLHttpRequest.responseText is the full web page, not the <form> ... </form> fragment that I saw being generated in XDEBUG.

 

After I poked around some, I did find the problem. Here's the offending bit of code...

 

Rq=getXMLHttpObj();
Rq.open('get', 'RequestForm.php?form=someform', true); // this line has the error
Rq.send(null);

 

Do you see the problem? The answer was in the Apache access.log file. When I looked there I saw that the page that Apache was processing for this request was "parentpage.php/RequestForm.php?form=someform". When I changed the "open" call as follows, everything started working properly...

 

Rq.open('get', '/RequestForm.php?form=someform', true); // this line is correct

 

Yes, that's right. Just adding a '/' to the start of the requested URL fixed the problem. At the moment, I'm calling this an Apache oddity. I'm reluctant to call this a bug - maybe it's supposed to work this way??

 

Anyway, I hope this helps someone else!!

 

Steve G.

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/88295-solved-ajax-oddity/#findComment-453535
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.