【问题标题】:call controller from a view in cakephp1.3, through javascript method通过 javascript 方法从 cakephp 1.3 中的视图调用控制器
【发布时间】:2014-03-16 20:48:31
【问题描述】:

我有一张地图,我想通过 javascript 从中进行选择,这是我的 googlemap 地图中的一个矩形区域。在此之后,我想通过将两个角坐标(我已经采取)发送到我的 Cakephp 控制器来执行一个操作,而无需单击任何地方。请问我该怎么做?

提示:我使用的是 1.3 cakephp 版本。谢谢。

这是我的代码:

var map, bnds, dz;

    function initialize() {

      ...

     dz= map.GetDragZoomObject();

     ...
     google.maps.event.addListener(dz,'dragend', function(bnds){


    //variable to be display: bnds
         alert('KeyDragZoom end: ' + bnds); 
   }

警报在警报框中显示此消息:

"KeyDragZoom end: ((1.53790123, 9.404296), (5.22600788, 18.391113281))

【问题讨论】:

  • 你可以使用Jquery post $.post(URl,{'Bounds':"pass your bounds here..."},function(response){ ..... });在 URL 部分中,您可以为要执行任何操作的操作提供 URL。

标签: javascript php ajax cakephp cakephp-1.3


【解决方案1】:

您可以尝试使用 jquery $.ajax 将数据发送回服务器。此示例也处理来自服务器的响应。

$.ajax({
    url: "<?php echo $html->url( array( 'controller' => 'xxx', 'action' => 'xxx' ), true ) ?>",
    dataType: "json",
    crossDomain: false,
    data: bnds
})
.then( function ( response ) {
    $.each(response, function (i, val) {
        // do something
    });
});

如果你需要的话,这里有 ajax 的文档https://api.jquery.com/jQuery.ajax/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2019-03-03
    相关资源
    最近更新 更多