php - call controller from a view in cakephp1.3, through javascript method

835

I have a map from which I want to select through javascript, a rectangular zone from my googlemap map. After this, I want to perform an action by sending the two corner coordonates (that I have took) to my Cakephp Controller, without clicking anywhere. How can I perform it please?

hint: I use the 1.3 cakephp version. Thanks.

here is my code:

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); 
   }

The alert shows me this message in a alertbox:

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

Answer

Solution:

you can try using jquery $.ajax to send the data back to the server. This example handles a response back from the server as well.

$.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
    });
});

The documentation for ajax is here if you need it https://api.jquery.com/jQuery.ajax/

People are also looking for solutions to the problem: php - Symfony2: How to set the locale manually?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.