Igor Martins
Igor Martins

Reputation: 2047

Ajax request isn't working in cakephp

I'm trying to do an ajax request in cakephp.
My submit is #enviar. My action is pages/contato.

This is my ajax request:

$(document).ready(function() {
    $('#enviar').click(function(){
        $.ajax({
            type: 'post',
        url:"<?php echo Router::url(array('controller' => 'pages','action' => 'contato')); ?>",
        })
    })
});

I change the $.ajax for a simple alert() and when i click submit this works.
Where is my problem?

Upvotes: 0

Views: 917

Answers (3)

user2082822
user2082822

Reputation: 73

Better change the url, in your ajax function :-

$.ajax({
        type: 'post',
    url:"http://localhost/teste/pages/contato"
    })

Upvotes: 1

Nunser
Nunser

Reputation: 4522

Have you tried with Html helper and an absolute path?

$.ajax({
    type: 'post',
    url: "<?=$this->Html->url(array('controller' => 'pages',
                                    'action' => 'contato'),
                              true);?>"
});

Upvotes: 0

Waqar Alamgir
Waqar Alamgir

Reputation: 9968

Add an .htaccess file to the working directory with the following code:

allow from all

Upvotes: 0

Related Questions