Ajax with POST data

Hi everyone,

I'm a newbie to the framework, and not so used to ask on forums…

I would need to join some POST data to a CHtml:ajax() event. How would you do that?

Many thanks

Ok, I achieved the same result using jQuery $.ajax:

$.ajax({

            "type": "POST",

            "data": $("form").serialize(),

            "dataType": "text",

            "success": function(msg){  },

            "error": function(){  },

            "url": 'index.php?r=point/echo',

            "cache": false

        });

Is that fine? :)

Yes, this is the way to go. Or you can use the shortcut provided by CHtml::ajaxSubmitButton() which will post the form via AJAX.

Hi, thank you for the reply.

This script is actually a part of a bigger javascript. Is it possible to send the content of Javascript variables dynamically?

Can I write something like:

myVar = 'Some Data';

$.ajax({

            "type": "POST",

            "data": myVar,

            "dataType": "text",

            "success": function(msg){  },

            "error": function(){  },

            "url": 'index.php?r=point/echo',

            "cache": false

        });