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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -