Jump to content

Make propper ajax call in module


Snade

Recommended Posts

Hi all,

 

I'm making a module which compiles .less file using LESSphp.

 

If I try to include lessc.inc.php in the module php file I got bunch of errors, but if I run a separate file it all works good. So I got compile.php with this content:

 

<?php
require "lessc.inc.php";
$less = new lessc;
echo $less->compileFile("cleantheme.less", "cleantheme.css");
?>

 

(if you have an idea how I can run this inside the module php file within class ModuleName extends Module{ , it will be great I guess)

 

If I run this script using normal link it all works good, new page is opened and the .less file is compiled

<a  target="_blank" href="'.$domain.__PS_BASE_URI__.'modules/themeeditor/compile.php">'.$this->l('Compile File').'</a>

 

The question is, How can I run this file without opening new window using AJAX ?

 

I tried this (and many variations of it) without success:

 


this is very basic version just to see what I was trying to get working, but not sure if I'm on the right direction

   <script type="text/javascript">
  $(document).ready(function() {
   $(#subbtn).click(function()
   {
    $.ajax({
	 url: "'.$this->_path.'compile.php"
    });
   });
  });   
   </script>

 

 

Any help will be really appreciated

Link to comment
Share on other sites

Hello,

 

If I try to include lessc.inc.php in the module php file I got bunch of errors, but if I run a separate file it all works good.

 

Perhaps you missed out something there. Just out of curiosity, I coded a simple module with lessphp 0.3.9 and it works out of the box. Please find it attached.

Also, remember to set the proper permissions to let apache user write into the module directory [PS/modules/less] as it will write the css output to a file there.

 

I hope this helps.

less.zip

Link to comment
Share on other sites

Thank you very much my friend :)

 

I think my problem was that I did not include the less.inc.php in the construct ... dunno why I made this mistake...

 

Thanks again for spending time to make this module, that was really helpful.

 

I have one more question, is there a way to make the .css file that is hooked in the head, to be always the last .css file ? even if I put my module on the last position in the back office, the css file is not the last one...

Edited by Snade (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...