html - send form data to php using ajax -
i know repetitive question, please me. have code send form data php using ajax, code doesn't work , don't know why. please ?
<html> <head> <script src="http://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script> <script> function chk(){ var name = document.getelementbyid('name').value; var datastring = 'name = ' + name; $.ajax({ type:"post", url:"hi.php", data: datastring, cache:false, success: function(html){ $('msg').html(html); } }); return false; } </script> </head> <body> <form> <input type="text" name="id" > <input type="submit" value="submit" onclick="return chk()"> </form> <p id="msg"></p> </body> </html>
php
<?php if($_post) { $name=$_post['name']; echo $name."<br>"; } ?>
this won't anything:
$('msg').html(html);
because there no <msg>
tags in markup. perhaps meant reference element id
of "msg"
?:
$('#msg').html(html);
Comments
Post a Comment