I have a page called formular.php that has the following code:
if(isset($_POST['date'])){
$date = ($_POST['date']);
echo "Data: ".$date;
}
The page also has a form with a JQuery datepicker:
<form id="myform" name="myform">
<input type="text" id="datepicker" name="datepicker"/>
</form>
And also, the JS code:
$(function() {
$( "#datepicker" ).datepicker({
minDate: 0,
onSelect: function(dateText, inst) {
$.ajax({
type: 'POST',
data: {date : dateText},
success: function(resp){
if(false !== resp){
alert(dateText);
}
}
});
}
});
});
When I select the date in datepicker, the javascript alert works fine. Even so, the isset of PHP always returns false. That is, for some reason Ajax is not reloading the page with the $_POST
value. Is there a problem in the above code or some more efficient method of doing this variable pass?
The result of the resp variable is:
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8"/>
<title>Dashboard I Admin Panel</title>
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]--><linkrel="stylesheet" href="jquery-ui-1.11.4.custom/jquery-ui.css" />
<!-- Load jQuery JS -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script><!--LoadjQueryUIMainJS--><scriptsrc="jquery-ui-1.11.4.custom/jquery-ui.js"></script>
<!-- Load SCRIPT.JS which will create datepicker for input field -->
<script type="text/javascript">
$(function() {
$( "#datepicker" ).datepicker({
minDate: 0,
onSelect: function(dateText, inst) {
$.ajax({
type: 'POST',
data: {date : dateText},
success: function(resp){
alert(resp);
}
});
}
});
});
</script>
</head>
<body>
<span id="hoverdata"></span>
<header id="header">
<hgroup>
<h1 class="site_title"><a href="index.html">Website Admin</a></h1>
<h2 class="section_title">Dashboard</h2><div class="btn_view_site"><a href="http://www.medialoot.com">View Site</a></div>
</hgroup>
</header> <!-- end of header bar -->
<section id="secondary_bar">
<div class="user">
<p>John Doe (<a href="#">3 Messages</a>)</p>
<!-- <a class="logout_user" href="#" title="Logout">Logout</a> -->
</div>
<div class="breadcrumbs_container">
<article class="breadcrumbs"><a href="index.html">Website Admin</a> <div class="breadcrumb_divider"></div> <a class="current">Dashboard</a></article>
</div>
</section><!-- end of secondary bar -->
<aside id="sidebar" class="column">
<form class="quick_search">
<input type="text" value="Quick Search" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
</form>
<hr/>
<h3>Content</h3>
<ul class="toggle">
<li class="icn_new_article"><a href="#">New Article</a></li>
<li class="icn_edit_article"><a href="#">Edit Articles</a></li>
<li class="icn_categories"><a href="#">Categories</a></li>
<li class="icn_tags"><a href="#">Tags</a></li>
</ul>
<h3>Módulos de Avaliação</h3>
<ul class="toggle">
<li class="stats_graph"><a href="#">New Article</a></li>
<li class="icn_edit_article"><a href="#">Edit Articles</a></li>
<li class="icn_categories"><a href="#">Categories</a></li>
<li class="icn_tags"><a href="#">Tags</a></li>
</ul>
<h3>Users</h3>
<ul class="toggle">
<li class="icn_add_user"><a href="#">Add New User</a></li>
<li class="icn_view_users"><a href="#">View Users</a></li>
<li class="icn_profile"><a href="#">Your Profile</a></li>
</ul>
<h3>Media</h3>
<ul class="toggle">
<li class="icn_folder"><a href="#">File Manager</a></li>
<li class="icn_photo"><a href="#">Gallery</a></li>
<li class="icn_audio"><a href="#">Audio</a></li>
<li class="icn_video"><a href="#">Video</a></li>
</ul>
<h3>Admin</h3>
<ul class="toggle">
<li class="icn_settings"><a href="#">Options</a></li>
<li class="icn_security"><a href="#">Security</a></li>
<li class="icn_jump_back"><a href="#">Logout</a></li>
</ul>
<footer>
<hr />
<p><strong>Copyright © 2011 Website Admin</strong></p>
<p>Theme by <a href="http://www.medialoot.com">MediaLoot</a></p>
</footer>
</aside><!-- end of sidebar -->Array
(
[date] => 03/24/2016
)
Data: <span id='a-data'>03/24/2016</span>
<section id="main" class="column">
<form id="myform" name="myform">
<input type="text" id="datepicker" name="datepicker"/>
<input type="button" id="submitMe">
</form>
<div class="spacer"></div>
</section>
</body>
</html>
Thank you.