1

why does my symfony2 Form not submit? when I click on the submit button, the error message I declare displays !

$(document).ready(function(){
$("#addemail").submit(function(){ 
            var mail = $("#email").val()  ;
                $.ajax({
                    type : "POST",
                    url  : "{{ path('store_mailListe') }}",
                    data : {
                            email : mail
                    },
                            success : function(data){
                                alert(mail);
                                if (data === "true") {
                                     alert(data);
                                    $("#email-true").html('<div class="b-shortcode-example"><div class="b-alert-success f-alert-success"><div class="b-right"><i class="fa fa-times-circle-o"></i></div><div class="b-remaining"><i class="fa fa-check-circle-o"></i> Thank you!</div></div> </div>');
                                    return true;
                                }else{
                                        alert(data);
                                        $("#email-true").html('<div class="b-shortcode-example"><div class="b-alert-success f-alert-success"><div class="b-right"><i class="fa fa-times-circle-o"></i></div><div class="b-remaining"><i class="fa fa-check-circle-o"></i> Sorry can you try again</div></div> </div>');
                                    return false;
                                    }

                            }
                });
               return false;
    }); 

}); The alert(mail) show My email, but alert(data) show a HTML code of page. in the controller a make print_r();die(); but nothing happening Thanks for your help.

M-BNCH
  • 393
  • 1
  • 3
  • 18

1 Answers1

0

Using AJAX, the POST requests are not visible on client side.

If you want see your print_r();die;, you must open your console before submit, in the network tab, and after submit, open the POST request created in the list, and see the Preview or Response tabs.

The returned HTML of your alert(data) is surely a Symfony2 PHP error, like those that you can see on a GET route, or just the response returned by your POST method. Open the Preview tab of your Network browser console, you'll see your PHP error returned by Symfony on the request route, as HTML preview.

Your data variable represent your response returned by your Symfony POST action, if you return your email, this will be your email, if you return true in success, it will be true.

How to integrate Ajax with Symfony2

Community
  • 1
  • 1
chalasr
  • 12,971
  • 4
  • 40
  • 82