1

When a form sends variable with GET Method, the URL changes, putting the variables that you are passing in this way

url?variable=....

How can I get the same result with jQuery Ajax? Is it possible? Thank you

mgraph
  • 15,016
  • 4
  • 38
  • 73

1 Answers1

0

set path in your php layout/view file where you include this code

<script>
   var path="<?php echo $this->webroot;?>";
</script>

and add following jquery code to post the data through ajax.

$.ajax({
         type: 'POST',
         url: path+'homes/createEvent',
             data: {eventname:eventname,manager:manager},
         async: false,
         success: function(resulthtml)
                 {
        alert(resulthtml);
         },
         error: function(message)
                 {
        alert('error');
         }  
});

and on homes_controller.php, u will get this ajax data in createEvent function,

<?php
    function createEvent()
    {
       $eventName=$_POST['eventname'];
       $manager=$_POST['manager'];
    }
?>
Suhel Meman
  • 3,592
  • 1
  • 16
  • 26