php - How to return the result of a function in the same page using jQuery? -
this simple don't seem able make happen in codeigniter.
using simple php should be:
<form id="volume" method="post" action="<?php echo $php_self;?>"> <label>length(cm):</label> <input type="text" name="length"> <label>width(cm):</label> <input type="text" name="width"> <label>height(cm):</label> <input type="text" name="height"> <button type="submit">submit</button> </form> <?php $length = $_post["length"]; $width = $_post["width"]; $height = $_post["height"]; $variable = 5000; $sum_total = ($length * $width * $height) / $variable; printf ("%01.2f" , $sum_total); ?> kg
i put form in view, php in controller want return result in same page instead of redirecting me.
thank in advance responses.
put jquery similar on page submit button.
$(document).ready(function(){ $('#volume').submit(function(event){ event.preventdefault(); var post_array = { length: $('input[name=length]').val(); width: $('input[name=width]').val(); // etc }; $.post('path/to/controller/method', post_array, function(data){ alert(data); // stuff; } return false; //to stop form submitting }); });
put php calculates result in 'path/to/controller/method' , have return $result;
.
when user clicks submit button submit ajax request new view , return result jquery can change page or w/e want do.
Comments
Post a Comment