You can execute any codes before action method on controller run with beforeAction() method. For example, you want to make every action method are JSON type on content. So, you can add method like this on your controller:
protected function beforeAction($action){
header('Content-Type: application/json');
return parent::beforeAction($action);
}
its will be effected to all actionAny() to JSON as type of content
Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts
Wednesday, March 04, 2015
Simple jQuery Ajax Post Sending
Sending POST data to server using jQuery is very simple. I assumed that you sending POST data when the DIV with id:#sendme is clicked. So, you can use codes like this:
$("#sendme").click(function(){
});
$.post("URL POST",
{
param1: "value1",
param2: "value2"
},
function(data, status){
});
});
- URL POST can be replaced with your URL post
- param1 and param2 are name of post data
- value1 and value2 are value of param that will be sent to URL POST
Subscribe to:
Posts (Atom)