我是 jquery ajax 的新手。我在 cakephp 工作,我有以下事情要做:我有 7 个链接:sun, mon, tue, wed, ...
现在单击每个链接,我希望将该链接的文本存储到一个可以在控制器中访问的数组中。我希望使用 jquery ajax 来做到这一点。
以下是我的代码不起作用(jquery ajax 测试代码):
<?php
echo $this->Html->link('sun',
array('onclick' => 'callAjax();'),
array('class' => 'dayss'));
?>
<script>
function callAjax() {
$.ajax({
url: "rideoffers/ride_offer",
type: "POST",
success: function() {
console.log("hi");
},
error: function() {
console.log("error");
}
});
return true;
}
</script>
上面的代码不会打印 hi 或错误。我哪里错了?我该如何解决?
编辑:迪佩什帕尔马
<pre>CakeRequest Object
(
[params] => Array
(
[plugin] =>
[controller] => Rideoffers
[action] => ride_array
[named] => Array
(
)
[pass] => Array
(
)
)
[data] => Array
(
)
[query] => Array
(
)
[url] => Rideoffers/ride_array
[base] => /carpooling
[webroot] => /carpooling/
[here] => /carpooling/Rideoffers/ride_array
[_detectors:protected] => Array
(
[get] => Array
(
[env] => REQUEST_METHOD
[value] => GET
)
[post] => Array
(
[env] => REQUEST_METHOD
[value] => POST
)
[put] => Array
(
[env] => REQUEST_METHOD
[value] => PUT
)
[delete] => Array
(
[env] => REQUEST_METHOD
[value] => DELETE
)
[head] => Array
(
[env] => REQUEST_METHOD
[value] => HEAD
)
[options] => Array
(
[env] => REQUEST_METHOD
[value] => OPTIONS
)
[ssl] => Array
(
[env] => HTTPS
[value] => 1
)
[ajax] => Array
(
[env] => HTTP_X_REQUESTED_WITH
[value] => XMLHttpRequest
)
[flash] => Array
(
[env] => HTTP_USER_AGENT
[pattern] => /^(Shockwave|Adobe) Flash/
)
[mobile] => Array
(
[env] => HTTP_USER_AGENT
[options] => Array
(
[0] => Android
[1] => AvantGo
[2] => BlackBerry
[3] => DoCoMo
[4] => Fennec
[5] => iPod
[6] => iPhone
[7] => iPad
[8] => J2ME
[9] => MIDP
[10] => NetFront
[11] => Nokia
[12] => Opera Mini
[13] => Opera Mobi
[14] => PalmOS
[15] => PalmSource
[16] => portalmmm
[17] => Plucker
[18] => ReqwirelessWeb
[19] => SonyEricsson
[20] => Symbian
[21] => UP\.Browser
[22] => webOS
[23] => Windows CE
[24] => Windows Phone OS
[25] => Xiino
)
)
[requested] => Array
(
[param] => requested
[value] => 1
)
)
[_input:protected] =>
)
</pre>