is it possible to call user_ajax.php function through article with sourcerer ?

kouros91

Member
Hi. I would like to run an ajax function through an article with sourcerer .
But it doesn't work.

My code in user_ajax is :
PHP:
    public function return_nbconnect()
    {
        $db = FabrikWorker::getDbo();
        //$query = $db->getQuery(true);
        $retStr = '';
        $app = JFactory::getApplication();
        $input = $app->input;
       
        $Idadh = $input->get('vari', '');
       
      
        $user = JFactory::getUser();
        $IDmy= $user->id;
        $query = $db->getQuery(true);
        $query->select('session_id,userid')->from('g363_session')->where('userid = ' . $db->quote($IDmy));
        $db->setQuery($query, 1, 0);
        //$result = $db->loadResult();
        $result = $db->loadObjectList();
        // Retrieve each value in the ObjectList
        foreach( $result as $row ) {
            $this_user_userid = $row->userid; 
            $this_user_session_id = $row->session_id;  
        }

        $retStr = (string) $this_user_session_id;
        echo $retStr;
    }
and my code in the article through sourcerer is :
JavaScript:
function return_nbconnect(xxy) {

  var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=return_nbconnect&vari=" + xxy;

  new Request({url:url,

  onComplete: function(response) {

  if (response != '') {

  alert(response);

  }

  }

  }).send();

}

vari = 3;

return_nbconnect(vari);

I don't care vari. Just i didn't know if it works if i don't send a value.
The function must resend if connexion for a userid already exists.

Thank you for help :)
Nicolas
 
I presume that's not the whole code in your user_ajax.php, that it's wrapped in the "class UserAjax { ... }".

-- hugh
 
Yes This function is in the class UserAjax.But that doesn't work. I'm going to try with a fabrik form instead of an article.
 
It should work through Sourcerer, although it kind of depends how you are firing your code. If you want it to run on load, probably best to hang it on an event ...

Code:
jQuery( document ).ready(function() {
   vari =3;
   return_nbconnect(vari);
});
 
The other thing to do is to test your actual AJAX PHP, by just entering the URL in your browser by hand ...

Code:
http://yoursite.whatever/index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=return_nbconnect&vari=3

...and it should output whatever it is your code echos. If it doesn't, make sure you enable full error reporting in J!'s global settings, and see if it throws a PHP error. And/or use te usual var_dump debugging method to see what you variables are being set to, what your query is, etc.

-- hugh
 
Ok Thank you very much . I have now another problem with script php cron . I have opened a thread for this issue.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top