[英]Ajax request isn't working in cakephp
I'm trying to do an ajax request in cakephp. 我正在尝试在cakephp中执行ajax请求。
My submit is #enviar
. 我的提交是
#enviar
。 My action is pages/contato
. 我的动作是
pages/contato
。
This is my ajax request: 这是我的ajax请求:
$(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. 我将$ .ajax更改为一个简单的
alert()
,当我单击提交时,此方法有效。
Where is my problem? 我的问题在哪里?
Better change the url, in your ajax function :- 在您的ajax函数中更好地更改URL:-
$.ajax({
type: 'post',
url:"http://localhost/teste/pages/contato"
})
使用以下代码将.htaccess文件添加到工作目录中:
allow from all
Have you tried with Html helper and an absolute path? 您是否尝试过HTML Helper和绝对路径?
$.ajax({
type: 'post',
url: "<?=$this->Html->url(array('controller' => 'pages',
'action' => 'contato'),
true);?>"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.