en Jump to content
  • 0
Sign in to follow this  

Call Ajax not working


I've created a custom form with star ratings. I am using ajax to send the form,  but ajax not working. I do not receive errors and the status is OK: 200.Where am I doing wrong?
This is the structure of the tpl file
    <div class="starrr" id="rating-comment"></div>  
<div id="commentFormBody">         
        <textarea id="comment" rows="10" cols="50"></textarea>
  <div id="commentSubmitButton">
        <input type="submit" id="submit" value="submit" />                

<!-------- STAR RATING -------->
<script  type="text/javascript">
var rating;
    change: function(e, value){
        rating = value;
        if (value) {
        else {
<!-------- AJAX SUBMIT ------>
$('#submit').click(function() {        
    var comment = $('#comment').val();               
   var baseDIR = 'http://localhost:8080/shop/' 
           url: baseDIR + 'modules/mymodule/controllers/front/save.php',          
           type: 'POST',                                               
          data: {
         comment: comment, 
         rating: rating,
         ajax: true,        
        success: function(status)

This is the php file

if (!defined('_PS_VERSION_'))

class MymoduleSaveModuleFrontController extends ModuleFrontController
    public function initContent()
        $rating = (int)Tools::getValue('rating');
        $comment = trim(Tools::getValue('comment'));                                   
            Db::getInstance()->insert('comments', array(                    
                        'rating'  => $rating,
                        'comment' => $comment,

Thank you, I'm sorry if I'm presenting the problem here

Share this post

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

thanks for the answers, but despite several tests, also referring to the link you told me, the problem remained. So I solved it by changing the structure.

One question: in addition to using {literal} {/ literal}, is there another way to insert a js file in the tpl file to keep it separated? I tried using:

<script type = "text / javascript">
   <src = ",,,,,,,">
</ script>

 but nothing happens.

Share this post

Link to post
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
Sign in to follow this  


Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More