Submit Form and return values using HTML / JQuery / PHP -
need ... homepage have 3 divs, #header, #content, #footer. other pages being opened inside #content div. in 1 of pages have form 2 select lists , 1 submit button. want click button , return page #content div, showing values select before. this:
the origin is: 1
destiny is: 1
but code returns following ...
notice: undefined variable: origin in ... notice: undefined variable: destiny in ...
note: working if don't open page inside #content div
my html:
<form id="myform" name="myform" action="values.php" method="post"> <select id="origin" name="origin"> <option value="0" selected>-- select origin --</option> <option value="1">portugal</option></select> <select id="destiny" name="destiny"> <option value="0" selected>-- select destiny --</option> <option value="1">lisboa</option></select> <input id="btsubmit" name="btsubmit" type="submit" value="search!"> </form>
my function:
$(document).ready(function(){ $('#btsubmit').click(function(e) { e.preventdefault(); var url = $('#myform').attr('action'); var method = $('#myform').attr('method'); $.ajax({ type: method, url: url, data: $('#myform').serialize(), success: $('#content').load(url) }); }); });
my values.php page:
<?php if(isset($_post['origin']) || isset($_post['destiny'])) { $origin = $_post['origin']; $destiny = $_post['destiny']; } echo 'the origin is:' . $origin . '<br>'; echo 'the destiny is:' . $destiny; ?>
you should not call load
again - have called $.ajax
, received results. need display them in content
:
success: function (data) { $('#content').html(data); }
Comments
Post a Comment