php - Kohana - how to create form without refresh? -


how create jquery + ajax form without refresh? controller , views:

http://pastebin.com/gl5xvxfz

in "clear" php create this:

$(document).ready(function(){     $("form#submit").submit(function() {      var note = $('#note').attr('value');          $.ajax({             type: "post",             url: "add.php",             data: "note="+ note,             success: function(){                 $('form#submit').hide(function(){$('div.success').fadein();});              }         });     return false;     }); }); 

in add.php file insert database.

there more complicated ways of doing example detecting ajax request in action , if detected print out javascript response. way is

javascript

function postform(note){      $.ajax({       url  : '/controller/action',       type : 'post',       data : 'note='+note,       success : function(jsn){         var json = $.parsejson(jsn);         if(json.status == 200)           alert('completed successfully');         else           alert('not completed successfully');       },       error : function(xhr){         //debugging         console.log(xhr);       }        });    } 

php

  <?php     class controller_controllername extends controller_template{       public $template = 'template';        public function action_index(){}        public function action_form(){         $this->auto_render = false; // <-edited         $array = array();          //processing form code here          if($success){           $array['status'] = 200;         }else{           $array['status'] = 500;          }          print json_encode($array);       }      } ?> 

this example have done without testing surely should enough work on


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -