Hi,

Really sorry, great place for answers here but it seems I've made a stupid
mistake. In certain cases the php code in question redirects to a different
page returning that in the ajax response instead of the section I needed.

Thanks for you help anyway much appreciated.


weierophinney wrote:
> 
> -- moesian <[email protected]> wrote
> (on Tuesday, 13 October 2009, 12:28 AM -0700):
>> 
>> Hi I'm having a problem in Firefox detecting if the request is
>> xmlHttpRequest
>> in my php code, my code seems to work fine when using IE and Chrome. I'm
>> using Magento which is based on the Zend Framework and using the Zend
>> isXmlHttpRequest() function to test whether or not the request is an xhr
>> one
>> or not. In Firefox this seems to return false even when I make an ajax
>> call
>> using Prototype.
> 
> If you're using FireBug (and if you're not, you should be), check to see
> what request headers are sent during your XHR call. 
> 
> What ZF does is look for the header:
> 
>     X-Requested-With: XMLHttpRequest
> 
> If that header isn't present, then isXmlHttpRequest() evaluates to
> false.
> 
> There are two ways to get around that situation:
> 
>  * Most JS toolkits allow you to pass custom headers when making an XHR;
>    good JS toolkits allow you to extend the functionality of the XHR
>    functionality to add the headers in so that *all* calls will add
>    them.
> 
>  * Alternately, send a special query parameter that you can check for in
>    your code. If you use the parameter "format", you can then also start
>    doing some fun stuff with the ContextSwitch action helper in ZF. :)
> 
>> Here's the prototype code, perhaps I'm doing something wrong here:
>> 
>> var shop = {
>> cart: {
>>              init: function(){
>>                      var product_forms  = $$('.ajax-add-to-cart');
>>                      if (!product_forms[0]) return;
>>                      product_forms.invoke('observe', 'submit', 
>> shop.cart.add);
>>              },
>>              add: function(e){
>>                      var ele = e.element();
>>                      ele.request({
>>                      onFailure: function() {},
>>                      onSuccess: function(t)
>> {$('header-cart').replace(t.responseText);}
>>                          });
>>                      Event.stop(e); // stop the form from submitting
>>                      
>>              },
>>              remove: function(productId){
>>                      
>>              }
>>      }
>> }
>> 
>> And here's the php code that tests if its an xhr request:
>> 
>>              if($this->getRequest()->isXmlHttpRequest())
>>              {
>>                      $this->loadLayout();    
>>                      
>> $this->getResponse()->setBody($this->_getSideCartHtml());
>>              }
>>              else
>>              {
>>                      Varien_Profiler::start(__METHOD__ . 'cart_display');
>>              $this->loadLayout();
>>              $this->_initLayoutMessages('checkout/session');
>>              $this->_initLayoutMessages('catalog/session');
>>             
>> $this->getLayout()->getBlock('head')->setTitle($this->__('Shopping
>> Cart Ajax 2'));
>>              $this->renderLayout();
>>              Varien_Profiler::stop(__METHOD__ . 'cart_display');
>>              }
>> 
>> Thanks in advance for any help, this one has me really scratching my
>> head.
>> -- 
>> View this message in context:
>> http://www.nabble.com/Firefox-Ajax-problem-tp25868337p25868337.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>> 
> 
> -- 
> Matthew Weier O'Phinney
> Project Lead            | [email protected]
> Zend Framework          | http://framework.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Firefox-Ajax-problem-tp25868337p25874988.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to