jquery - Ajax not working, PHP, AJAX -


i'm trying use ajax on select tag 2 options, it's not getting $_post reason. prints out "---", not print out $_post value, either 1 or 2. i'm not sure did wrong. please take @ code right here, , if figure out part of code wrong, please point out working example. thank you.

newtest.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>  <script type = "text/javascript">   function ajax(url,type,thename,id) {        $.ajax({            type: "post",            url: url,            data: { select: $(type+'[name='+thename+']').val()},            error: function(xhr,status,error){alert(error);},            success:function(data) {              document.getelementbyid( id ).innerhtml = data;            }        });  }  </script>  <?php  echo "<select name = 'name' onchange = 'ajax(\"newtestx.php\",\"input\",\"name\",\"output\")'>"; echo "<option value = '1'> 1 </option>"; echo "<option value = '2'> 2 </option>"; echo "</select>";  echo "<div id = 'output'></div>";  ?> 

newtestx.php

<?php  $name = $_post['name']; echo $name."---";  ?> 

you need change line:

echo "<select name = 'name' onchange = 'ajax(\"newtestx.php\",\"select\",\"name\",\"output\")'>"; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -