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,238
  • 4
  • 41
  • 75
  • 1
    Use the [`history.replaceState`](https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_replaceState().C2.A0method) method (or, change `location.hash`). – Rob W Jun 17 '12 at 09:34
  • do you have problem sending it or retrieving it – Raab Jun 17 '12 at 09:37
  • You're the 1000th person asking it, answer: http://stackoverflow.com/q/824349/601179 – gdoron Jun 17 '12 at 09:50

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,702
  • 1
  • 18
  • 26