Advertisement:

Author Topic: [solved] ajax in osclass  (Read 1003 times)

galtech

  • Newbie
  • *
  • Posts: 18
[solved] ajax in osclass
« on: September 19, 2016, 08:08:57 am »
hii

i have listed my categories in my page. on clicking any category i want to display my subcategories on the same page using ajax. i dont know how to use ajax in osclass

please help.
thanks
« Last Edit: September 20, 2016, 02:40:35 pm by galtech »

galtech

  • Newbie
  • *
  • Posts: 18
Re: ajax in osclass
« Reply #1 on: September 20, 2016, 08:33:33 am »
hi

i dont know is it is the right way or not, but i found one solution by editing one core file(oc-includes/osclass/controller/ajax.php)
i wrote my ajax function as new switch case this solved my problem but i think it is not a permanent solution because it will get lost when the osclass will get updated

if anyone have another solution please specify

thanks

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: [partially solved] ajax in osclass
« Reply #2 on: September 20, 2016, 10:42:28 am »
Modifying core files is always a bad idea. In the core you have this :

https://github.com/osclass/Osclass/blob/master/oc-includes/osclass/controller/ajax.php#L221

If you add a variable named "hook" to the ajax url, then it will launch a hook with that name (with "ajax_" before).
For example

Code: [Select]
http://example.com/index.php?page=ajax&action=runhook&hook=myownaction

Then, you could create a plugin

Code: [Select]
function myfunction() {
// DO STUFF HERE
}
osc_add_hook("ajax_myownaction", "myfunction");

There's something similar with the admin's ajax page

galtech

  • Newbie
  • *
  • Posts: 18
Re: [partially solved] ajax in osclass
« Reply #3 on: September 20, 2016, 02:40:15 pm »
hi

thanks for the reply. it worked for me  :)