0

This is my ajax request:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".emailfocusout").focusout(function(){
            $.ajax({
                url: '/checkout/Email/Email',
                type: 'POST',
                data: {'email': '[email protected]'},
                contentType: 'application/json',
                success: function(data) {
                    console.log('SUCCESS: ', data);
                },
                error: function(data) {
                    console.log('ERROR: ', data);
                },
            });
        });
    });
</script>

This is my controller:

public function EmailAction()
{
    // TODO: Implement me!  Here are some hints ;-)

    $email = $this->getRequest()->getParam('email');
    var_dump($email);
    echo $email;
}

I can't save - data: {'email': '[email protected]'} - to - $email = $this->getRequest()->getParam('email');

What am I doing wrong?

* UPDATE - SOLVED * I took data out of the ajax request. And in URL I put:

url: '/checkout/Email/Email/email/[email protected]',

I worked like that.

2
  • can you please upload your model file or database install script? Aug 5, 2018 at 16:24
  • Do you getting data in controller? Aug 5, 2018 at 18:35

3 Answers 3

0

just use only

data: '[email protected]',

and if you want to send dynamic email value use

data:'email='+$("input[name='email']").val(),
0

Change this,

    $.ajax({
                        url: '/checkout/Email/Email',
                        type: 'POST',
                        data: {'email': '[email protected]'},
                        contentType: 'application/json',
                        success: function(data) {
                            console.log('SUCCESS: ', data);
                        },
                        error: function(data) {
                            console.log('ERROR: ', data);
                        },
                    });

to

    $.ajax({
                        type: 'POST',
                        url: '/checkout/Email/Email',
                        data: {'email': '[email protected]'},
                        dataType: 'json',
                        success: function(data) {
                            console.log('SUCCESS: ', data);
                        },
                        error: function(data) {
                            console.log('ERROR: ', data);
                        },
                    });
0

In controller file you can try follow code.

$postData = $this->getRequest()->getPost(); $email = $postData['email'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.