Jump to content

Call Ajax not working


Recommended Posts

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

Link to comment
Share on other sites

  • razaro changed the title to Call Ajax not working
  • 3 weeks later...

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.

Link to comment
Share on other sites

  • 2 weeks later...

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...