Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

AJAX and cURL

AJAX and cURL

Dear Stephen, Congrats on a great product -

Please can you share a ? recipe or any samples - where in i can load / invoke some php statements asynchronously -

The problem i am facing - when trying to execute a cURL request in metamod pro - is that the entire page hangs up until the cURL is executed and html displayed -

I would like to be able to have each metamod module execute asynchronously - for whatever they have to do?

Is that possible -

Thanks a lot - in advance.

tcnrahul
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: AJAX and cURL

Hi tcnrahul,

ooooh, that's a tough one. I think that the direction that this has to go in is to transfer some of the logic to Javascript, and create some kind of AJAX module loader.

i.e.
- Metamod creates some JS rather than outputting/returning a module
- Javascript does an AJAX-type call back to Joomla, to some component that just outputs a requested module
- that module could itself be a MetaMod, which can then have as much logic in it as it needs to. It would not matter if it takes a second or two to calculate, as it's just being called in AJAX.

The things which would need to be built:
1 - a small component which simply returns the HTML for a given module, based on URL parameters. It would return it via a "raw" view (not HTML view) so that it would not have extra modules added around it.
2 - the JS code to be output by the original module, which would need to control:
  -- the display of a "progress" graphic
  -- calling the ajax with a given module id
  -- replacing the module with the HTML returned from AJAX.


Unfortunately I am not offering to create this - I hope someone else can pick up the challenge!

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: AJAX and cURL

Dear Stephen,

I will follow your lead and come back with something. If you can mentor me on this - and if it works -> I will offer it to you - in case other metamod users want it. I see a lot of value for it - but need help.

Thanks again.

tcnrahul
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: AJAX and cURL

I just discovered some good stuff that will help:

1 - RokModule by RocketTheme is a component that will output the contents of a module when called by AJAX etc. You specify the id of the module in the URL, e.g.: http://example.com/index2.php?option=co … duleid=XXX

2 - Mootools (which is normally loaded by default in Joomla) has some good AJAX functionality.

Ok, so here's a REAL basic script which worked for me on Joomla 1.5, using the old version of MooTools (1.11). The JS syntax changes for Mootools 1.2 and 1.3/4, so you would need to investigate this for newer versions of Mootools and Joomla.

Code:

// use some code here to determine which module

// you want it to display. I'm using module 18
// to test with.
$moduleid = 18;
// you need this following line to quit php mode and allow raw html:
?>
<div id="myModule"></div>
<script>
window.addEvent('domready', function() {

  var myModule = $('myModule');

  var url = '<?php echo JRoute::_("index2.php?option=com_rokmodule&moduleid=$moduleid"); ?>';

  var myAjax = new Ajax(url, {method: 'get', update: myModule }).request();

});
</script>
<?php
// need the preceding line to return to php mode
// again before the end of the MetaMod.

I tested this with com_rokmodule v1.2 available from http://www.rockettheme.com/extensions-d … -rokmodule

Enjoy!

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: AJAX and cURL

By the way - I found a security issue in RokModule v1.2 and reported it - they have now released v1.4. Please make sure you upgrade to the new version of RokModule!

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: AJAX and cURL

@Stephen > many thanks. I did try rokmodule and it seems to work fine - You are truly one of the best.

tcnrahul
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: AJAX and cURL

@Stephen - your example works in Joomla 1.5 but somehow does not work in 1.7 ( installed the 1.7 version)and checked. Is there a different syntax -
Did install rokmodule for 1.7.

Thanks a lot.

As a side - is the ajax request per mootools or will it work if jquery is being loaded too?

tcnrahul
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: AJAX and cURL

Dear Stephen - this is an Update -

1) In 1.7 - i used the format - /index.php?option=com_rokmodule&;tmpl=component&type=raw&module=&moduleid;

2) Looking at rokstock ? it looks for a formatted modulename param -  If you know this from the top of your head - it will be great to get your feedback.

Any way  1.5 works with index2.php - like a charm.

Thanks again

tcnrahul
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: AJAX and cURL

Hi,

the JS code I gave you earlier is tied to MooTools v1.1 which is the default in Joomla 1.5. Later versions of J1.5 and probably J1.7 have (I think) MooTools 1.2 which I am pretty sure has a different syntax for AJAX calls. Is that something you can try to track down and find some examples for? Of course, if your template is using jQuery then you can find a jQuery version quite easily too.

I had a look at J1.7 version of rokmodule and it takes a URL parameter of "moduleid" just like the J1.5 version does. So that part stays the same. The other parameters may be different. Are you saying that the format you mention above actually works for 1.7?

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: AJAX and cURL

No Stephen - it does not - in metamod - actually it does work as part of rokstock etc.

Importantly - jquery is soo? much better than mootools? - can you please give me a generic example of how i can include and run jquery in metamod -

will it be as simple as - including the .js and writing out the commands with html. I wanted to finish this outstanding stuff and decide 1.5 / 1.7

BTW - sent you an email so i can pay up the difference?

tcnrahul
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10772
Newest User:
alton29318
Members Online:
0
Guests Online:
163

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked