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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.