thara Posted June 29, 2013 Share Posted June 29, 2013 I am using this jquery code to send value from a dropdown select box to a php script.This is my jquery code : $('#filter-value').change(function(){ var filterValue = $(this).val(); //console.log(filterValue); $.ajax({ type: 'post', url: 'table.php', dataType: 'html', data: {filter: filterValue}, success:function(data){ alert(data); }, error:function (xhr, ajaxOptions, thrownError){ //On error, we alert user alert(thrownError); }, complete: function(){ //alert('update success'); } }); }); This is my HTML code for dropdown <form method="post" action=""> <select id="filter-value" name="filter"> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> </select> </form> Now I need to make a mysql query in my `table.php` page with value from dropdown and after making the query I want to get date to main page again.But in my php page I tried something to check is there the value come from dropdown but still I couldn't get it to echo.This is php : if ( isset($_POST['filter'])) { $filter = $_POST['filter']; echo $filter; } Cay you please tell me how can I do this?Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/279678-send-dropdown-value-to-php-using-jquery-ajax/ Share on other sites More sharing options...
ginerjm Posted June 29, 2013 Share Posted June 29, 2013 I have limited ajax experience, but I don't think you can do a post. You must do a get, passing your dropdown value as an argument of your url. Also - you can't do an echo in the background script since that is how you return answers to the caller. You can only do debugging type echos by running the script standalone until you are done developing it. At least that's how I do it. Quote Link to comment https://forums.phpfreaks.com/topic/279678-send-dropdown-value-to-php-using-jquery-ajax/#findComment-1438464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.