Topic: double response

Hello,
I've a already working xaJax program. My problem is, that I got two response from my query back.
For example, if I checked a radio-button I got the old as well as the new response. I want just one response. Can sombody help me or give me some tips?

Here is my code:

require_once (t3lib_extMgm::extPath('xajax') . 'class.tx_xajax.php'); 
... 

function main($content,$conf){ 
    ... 
    # xaJax 
    $this->xajax = t3lib_div::makeInstance('tx_xajax'); 
    $this->xajax->decodeUTF8InputOn(); 
    $this->xajax->setCharEncoding('utf-8'); 
    $this->xajax->debugOff(); 
    $this->xajax->statusMessagesOn(); 
    $this->xajax->registerFunction(array('tx_commercelisting_formData',&$this,'formData')); 
    $this->xajax->processRequests(); 
    $GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('xajax')); 
} 
... 
function formData($arg){ 
    $i = 0;      
    foreach($arg AS $key => $value){ 
         foreach($this->getInfoByAttributes($value,$key) AS $row){ 
             foreach($this->getAttributesByName($key) AS $att){ 
                if($att['uid'] === '5' || $att['uid'] === '8' || $att['uid'] === '9'){ 
                     $uid[$i] = $row['uid']; 
                     if($old !== $row['uid']){ 
                        $i++; 
                        $old = $row['uid']; 
                    } 
                    $this->setData($uid); 
                    $pic = $this->getPrevImage(); 
                } elseif($att['uid'] === '3'){ 
                    (int)$uid = $row['uid']; 
                    $this->setData($uid); 
                    $pic = ''; 
                } else { 
                    (int)$uid = $row['uid']; 
                    $this->setData($uid); 
                    $pic = '<img src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/'.$this->getCorrectFileName($row['internal_title']).'/'.$this->getCorrectFileName($value).'.jpg" title="'.$row['title'].'" />'; 
                } 
            } 
        } 
    } 
    $objResponse = new tx_xajax_response(); 
    $objResponse->addAssign('ergebnis_img', 'innerHTML', $pic); 
    $objResponse->addAssign('selected_array', 'innerHTML', $this->slectedAttribtues(3)); 
    return $objResponse->getXML(); 
} 
... 
function setData($data, $priceArticle=null){ 
    $sessionVars = $GLOBALS["TSFE"]->fe_user->getKey('ses','tx_commercelisting'); 
    if($priceArticle === null){ 
        $sessionVars[$this->article] = $data; 
    } else { 
        $sessionVars[$priceArticle] = $data; 
    } 
    $GLOBALS["TSFE"]->fe_user->setKey('ses','tx_commercelisting', $sessionVars); 
    $GLOBALS["TSFE"]->storeSessionData(); 
}

First response:

Array
(
    [xajax] => tx_commercelisting_formData
    [xajaxr] => 1218736198968
    [xajaxargs] => Array
        (
            [0] => <xjxquery><q>var=old_var</q></xjxquery>
        )

    [be_typo_user] => ea4323b6bae582580bf2be56e368d159
    [PHPSESSID] => 4ab7a36bdb825b77376947bc88924090
    [fe_typo_user] => 56fb37c325
    [tx_phpmyadmin] => a1e9973bbc5544748d3d74ef25e73e99
)

Second response:

Array
(
    [xajax] => tx_commercelisting_formData
    [xajaxr] => 1218736198968
    [xajaxargs] => Array
        (
            [0] => <xjxquery><q>var=new_var</q></xjxquery>
        )

    [be_typo_user] => ea4323b6bae582580bf2be56e368d159
    [PHPSESSID] => 4ab7a36bdb825b77376947bc88924090
    [fe_typo_user] => 56fb37c325
    [tx_phpmyadmin] => a1e9973bbc5544748d3d74ef25e73e99
)

Re: double response

It looks like you are getting two requests (which will produce two responses, I suppose).  The problem is likely with the event handler on the browser.

Can you show the code where you assign the event handler?  (this is likely a button onclick or form onsubmit)

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: double response

Yes of course! Here is the code.

<form name="tx_commercelisting_content_left_form" id="tx_commercelisting_content_left_form"  method="post">
  <table cellpadding="0" cellspacing="0">
        
        
        
        
        
        
        
        
        
          <tr class="tx_commercelisting_table_content">
            <td width="30">
              <input type="radio" name="number" value="Single" id="number_Single" checked="checked" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))" />
            </td>
            <td width="90">
              <label for="number_Single" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))"><img src="typo3conf/ext/commerce_listing/res/number/small/single.jpg" title="Single" /></label>
            </td>
            <td width="180">
              <label for="number_Single" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))">Single</label>
            </td>
          </tr>
        
          <tr class="tx_commercelisting_table_content">
            <td width="30">
              <input type="radio" name="number" value="Paar" id="number_Paar"  onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))" />
            </td>
            <td width="90">
              <label for="number_Paar" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))"><img src="typo3conf/ext/commerce_listing/res/number/small/paar.jpg" title="Paar" /></label>
            </td>
            <td width="180">
              <label for="number_Paar" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))">Paar</label>
            </td>
          </tr>
        
          <tr class="tx_commercelisting_table_content">
            <td width="30">
              <input type="radio" name="number" value="Freunde" id="number_Freunde"  onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))" />
            </td>
            <td width="90">
              <label for="number_Freunde" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))"><img src="typo3conf/ext/commerce_listing/res/number/small/freunde.jpg" title="Freunde" /></label>
            </td>
            <td width="180">
              <label for="number_Freunde" onClick="xajax_tx_commercelisting_formData(xajax.getFormValues('tx_commercelisting_content_left_form'))">Freunde</label>
            </td>
          </tr>
        
        </table>
</form>

What should I change? Thank for your help!

Re: double response

It appears that you are getting two responses because both the Label and the Radio button implement the onClick.  Perhaps when the label is clicked, it triggers it's own onclick, then also, the radio button onclick.

Try removing the onclick for each of the labels and see if the issue ceases.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: double response

Thank you very much! We've got the mistake! smile