<form method="post" action="index.php/home/index/captchaTest"> <input name="name" id="name" type="text" placeholder="name" /> <input name="age" id="age" type="text" placeholder="age" /> <input name="email" id="email" type="text" placeholder="email" /> <input name="captcha" id="captcha" type="text" placeholder="captcha" /> <img src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?'+Math.random();" /> <input name="tijiao" type="button" value="提交" /> </form> <script type="text/javascript" src="__STATIC__/js/jquery.min.js"></script> <script type="text/javascript"> $(':button').click(function(){ var para = {}; para['name'] = $('#name').val(); para['age'] = $('#age').val(); para['email'] = $('#email').val(); para['captcha'] = $('#captcha').val(); $.ajax({ type: "post", url: "{:url('captchaTest')}", data: JSON.stringify(para), contentType: "application/json; charset=utf-8", dataType: "json", success: function(result){ console.log(result); }, error: function(result){} }) }) </script>
public function captchaTest(){ $content = file_get_contents("php://input"); return json_decode($content, true); }