en Jump to content
  • 0
Sign in to follow this  
pippo67

Call Ajax not working

Question

Hello,
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>    
  </div>    
  <div id="commentSubmitButton">
        <input type="submit" id="submit" value="submit" />                
  </div>        
</div> 

<!-------- STAR RATING -------->
<script  type="text/javascript">
{literal}
var rating;
$('#rating-comment').starrr({    
    change: function(e, value){
        rating = value;
        if (value) {
            $(".your-choice-was").show();
            $(".choice").text(value);
        } 
        else {
            $(".your-choice-was").hide();
        }
    }
});  
<!-------- AJAX SUBMIT ------>
$('#submit').click(function() {        
    var comment = $('#comment').val();               
   var baseDIR = 'http://localhost:8080/shop/' 
   $.ajax({                          
           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

<?php
if (!defined('_PS_VERSION_'))
    exit;

class MymoduleSaveModuleFrontController extends ModuleFrontController
{    
    public function initContent()
    {                        
        parent::initContent();        
        $rating = (int)Tools::getValue('rating');
        $comment = trim(Tools::getValue('comment'));                                   
        if(!empty($comment))
        {                
            Db::getInstance()->insert('comments', array(                    
                        'rating'  => $rating,
                        'comment' => $comment,
                        
            ));
        }
        $this->setTemplate('save.tpl');        
    }    
}

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