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': 'che607@yahoo.com'},
                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': 'che607@yahoo.com'} - 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/me@example.com',

I worked like that.

  • can you please upload your model file or database install script? – Rohan Hapani Aug 5 '18 at 16:24
  • Do you getting data in controller? – Prashant Valanda Aug 5 '18 at 18:35
0

just use only

data: 'email=me@example.com',

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': 'che607@yahoo.com'},
                        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': 'che607@yahoo.com'},
                        dataType: 'json',
                        success: function(data) {
                            console.log('SUCCESS: ', data);
                        },
                        error: function(data) {
                            console.log('ERROR: ', data);
                        },
                    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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