jquery - Joomla 2.5 mootools ajax - Send parameters to component -


i have been searching hours solution issue. have standard component controller thus:

defined('_jexec') or die;  jimport('joomla.application.component.controller'); jimport( 'joomla.environment.request' );  class getajaxcontroller extends jcontroller {   function test()       {        $jinput = new jinput();        $myvar = $jinput->getvar('eventname');        print_r($_request);        $a = $_get['eventname'];        $event = jrequest::getvar( 'eventname' ) ;        $client = jrequest::getvar( 'client' ) ;           echo "client:".$client." event:".$event."*".$myvar;    } } 

(i have been trying multiple solutions why there nonsense in there pertinent code still there)

i call custom module thusly:

$urla = "index.php?option=com_getajax&task=test&format=raw"; $document = jfactory::getdocument(); $document->addscriptdeclaration("      function runbutton() {         var data = 'eventname=aname&client=aclient';        var url='$urla';        var request = new request({        url: url,        data: data,        method:'post',        onsuccess: function(responsetext){          document.getelementbyid('xml_result').innerhtml=responsetext;        }        }).post('eventname=foo&client=bar'); // had .post()        request.setheader('eventname', 'sdfsdfsdf'); // added    } "); 

the response contains hard coded "client: ... event" minus variables. in other words, response , ajax/jquery part of whole thing working fine, cannot seem life of me send parameters component. (or @ least, retrieve them in component)

i've firebugged , not in response. i've harded coded url , used simple $_get in controller no success;

$urla = "index.php?option=com_getajax&task=test&format=raw&event=foo&client=bar"; 

i have tried , without sef urls. , can see controller i've tried various methods capture passed params. i've tried both 'get' , 'post'.

i have tried commonly posted solutions btw, i'm figuring has joomla stipping url parameters out in obscure way developers mother appreciate.

  • in firebug, there 'x' parameter showing i'm not sending appears empty. don't know if that's important or not.

any great.

thanks in advance, jeff

in case finds useful, needed parse down basics work.

this involved trial , error though, , don't claim understand of yet.

controller:

define( '_jexec', 1 );  // need various libraries first joomla specific controls  jimport( 'joomla.application.component.controller' ); jimport( 'joomla.environment.request' );  // extend jcontroller   class getajaxcontroller extends jcontroller {    // 'test' function 'task' can call in url name 'test'    // (we can have many simple defining new functions within our jcontroller class)      function test() {          $app =& jfactory::getapplication();          // vars posted module          $foo = jrequest::getvar('avar');         $bar = jrequest::getvar('bvar');         $result = dosomethingwiththem($foo,$bar);          // encode result , send back.          // (using json encoding allows multiple return variables. not used here.)           if($result) echo json_encode(array('test' => $result));          // need flush , close prevent else our data going          $app->close();         return;     } }  // helper functions can in controller not in jcontroller class  function dosomethingwiththem($foo,$bar) {    return $foo . $bar; } 

module:

define('_jexec', 1);  // bring in mootools (which i'm not convinced needed here, works so...)  jhtml::_( 'behavior.mootools' ); jhtml::_( 'behavior.framework', true );  // add jscript rendered page  $document->addscriptdeclaration("     // add function element event (a button in case)    jquery('#btgetajax').live('click', function() {        var avar = "something";       var bvar = "something else";        // call ajax component. notice task=test.        // format=raw further asks component return our data        var url='index.php?option=com_getajax&task=test&format=raw';        // json encode data we're sending controller        var dat = {'avar':avar, 'bvar':bvar};        // send via ajax        jquery.ajax({           url: url,          method: 'post',          data: dat,          datatype:'json',          success: function(data) {             alert(data.test);          },          error:function(xhr, status, data) {             alert(status);          }        });    }); "); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -