Loading


Advertisement:

Author Topic: Using Ajax call from within theme without breaking Osclass helpers?  (Read 665 times)

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 1573
  • osclass.work
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #15 on: March 04, 2017, 02:31:54 am »
Hi SmaRTeY, maybe you already figured this in the meantime, no, just "ajax" is enough.

Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2232
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #16 on: March 04, 2017, 03:38:18 am »
Nope, I was still contemplating how this works from a developers point of view :)

I will have a look at this tomorrow but it doesn't feel good to be honest because this way I would be having a 'page' within my 'pages'.
I use pages in admin only for creation of 'external' pages on front-end.

BUT maybe I still have the wrong idea here 8)

Web-Media

  • Sr. Member
  • ****
  • Posts: 294
  • Web
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #17 on: March 04, 2017, 10:09:02 am »
 .  Create a plugin folder  with all the files you need inside your theme. On theme activate copy the plugin folder from your theme to plugins folder (oc-content/plugins ).
On theme deactivate  delete  your plugin from plugins folder
 There is no need to activate your plugin and  Your theme  will use ajax file fom  oc-content/plugins/your-plugin .

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2232
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #18 on: March 04, 2017, 02:16:33 pm »
This is also an interesting solution Web-Media!
In this case the oc-load would not be needed and I would be able to use the osclass function 'osc_ajax_plugin_url($file)' correct?

.  Create a plugin folder  with all the files you need inside your theme. On theme activate copy the plugin folder from your theme to plugins folder (oc-content/plugins ).
On theme deactivate  delete  your plugin from plugins folder
 There is no need to activate your plugin and  Your theme  will use ajax file fom  oc-content/plugins/your-plugin .

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2232
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #19 on: March 04, 2017, 02:43:14 pm »
Interesting, _CONEJO answered similar question but here it focusses only on the use of Params class.
http://forums.osclass.org/general-help/params-class-not-working-out-side-of-osclass/?topicseen

Regards,
Eric

Web-Media

  • Sr. Member
  • ****
  • Posts: 294
  • Web
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #20 on: March 04, 2017, 02:53:31 pm »
Yes . You could use ajax plugin url ..  if plugin is moved  on theme activate
Second u could  use runhook  from main ajax controller    .. osc_add_hook ( ajax_your_function
 3 rd  you could use custom from main ajax and define route . Inside your theme.
 I'm mobile .. cannot give example code right now 

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2232
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #21 on: March 04, 2017, 07:33:17 pm »
Yeps, that is like having a 'real' plugin.
I am still thinking what would be best common practice
I mean, I choose not to create a plugin otherwise I would have so I thought let's just add this to theme but then came to know it's not working without the need of re-registering Osclass classes.

Why are all classes available in theme files and why not when adding an ajax file to active theme being called from within that theme?
I guess that's kinda basic webdev stuff I am still less familiar with.

Yes . You could use ajax plugin url ..  if plugin is moved  on theme activate
Second u could  use runhook  from main ajax controller    .. osc_add_hook ( ajax_your_function
 3 rd  you could use custom from main ajax and define route . Inside your theme.
 I'm mobile .. cannot give example code right now

Web-Media

  • Sr. Member
  • ****
  • Posts: 294
  • Web
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #22 on: March 05, 2017, 03:16:59 pm »
hy SmaRTeY .
try this :
Code: [Select]
function ajax_SmaRTeY ()
    {
 do stuff
}
osc_add_hook('ajax_SmaRTeY', 'ajax_SmaRTeY');

front end use this:
Code: [Select]
url: "<?php   echo osc_ajax_hook_url('ajax_SmaRTeY'); ?>"

<?php echo osc_ajax_hook_url('ajax_SmaRTeY', array('id' => $id ) )?>
<?php echo osc_ajax_hook_url('ajax_SmaRTeY', array('id' => $id,'smart'=>$smart ) )?>

back end
Code: [Select]
osc_admin_ajax_hook_url('ajax_SmaRTeY')
just keep the ajax_xxxxx
« Last Edit: March 05, 2017, 03:24:34 pm by Web-Media »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2232
Re: Using Ajax call from within theme without breaking Osclass helpers?
« Reply #23 on: March 06, 2017, 01:54:43 am »
Hi Web-Media,

I think I understand what to do and will do some playing around.
This hook is also in hPlugins I see but never came to my mind!

Thanks, will let you know if I succeeded!

hy SmaRTeY .
try this :
Code: [Select]
function ajax_SmaRTeY ()
    {
 do stuff
}
osc_add_hook('ajax_SmaRTeY', 'ajax_SmaRTeY');

front end use this:
Code: [Select]
url: "<?php   echo osc_ajax_hook_url('ajax_SmaRTeY'); ?>"

<?php echo osc_ajax_hook_url('ajax_SmaRTeY', array('id' => $id ) )?>
<?php echo osc_ajax_hook_url('ajax_SmaRTeY', array('id' => $id,'smart'=>$smart ) )?>

back end
Code: [Select]
osc_admin_ajax_hook_url('ajax_SmaRTeY')
just keep the ajax_xxxxx