Php 通过Ajax传递日期值
我有两种方法通过Ajax传递我的日历值。问题是,日期值仅在选择日期的第二次尝试后传递,并且它正在传递第一次尝试值 以当前结果为例: 第一次尝试时,我将选择:2017-03-01 selectvalueds='' 第二次尝试时,我将选择:2015-05-30 Selectvalueds='2017-03-01' 重要:强> 由于一些计算,我必须首先将calendar的值复制到#start,然后通过Ajax将#start传递给我的php代码。 Javascript:Php 通过Ajax传递日期值,php,jquery,ajax,joomla,Php,Jquery,Ajax,Joomla,我有两种方法通过Ajax传递我的日历值。问题是,日期值仅在选择日期的第二次尝试后传递,并且它正在传递第一次尝试值 以当前结果为例: 第一次尝试时,我将选择:2017-03-01 selectvalueds='' 第二次尝试时,我将选择:2015-05-30 Selectvalueds='2017-03-01' 重要: 由于一些计算,我必须首先将calendar的值复制到#start,然后通过Ajax将#start传递给我的php代码。 Javascript: $('#calendar').cha
$('#calendar').change(function() {
$('#start').val($(this).val());
});
$('#calendar’).change(function(){
var selectvalueds = $('#start').val();
Unit_id.html('<option value="">Loading...</option>');
if (selectvalueds == '')
{Unit_id.html(initial_Unit_html);}
else
{
$.ajax({
url: 'index.php',
data:'option=com_myapp&task=getUnitsHTML&dsvalue='+selectvalueds,
success: function(output) {
Unit_id.html(output);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + ' ' + thrownError);
}
});
}
});
$(“#日历”).change(函数(){
$('#start').val($(this.val());
});
$(“#日历”).change(函数(){
var selectvalueds=$('#start').val();
Unit_id.html('Loading…');
如果(selectvalueds=='')
{Unit_id.html(首字母_Unit_html);}
其他的
{
$.ajax({
url:'index.php',
数据:'option=com\u myapp&task=getUnitsHTML&dsvalue='+selectvalueds,
成功:功能(输出){
单位\u id.html(输出);
},
错误:函数(xhr、ajaxOptions、thrownError){
警报(xhr.status+“”+thrownError);
}
});
}
});
php:
公共函数getUnitsHTML(){
$jinput=JFactory::getApplication()->输入;
$db=JFactory::getDbo();
$query=$db->getQuery(true);
$sdate=date\u create($jinput->get('dsvalue');
$mystartdate=date_格式($sdate,“Y-m-d”);
回显“.$mystartdate.”;
}
您正在将两个更改事件绑定到#日历。相反,请尝试以下方法:
function yourCalculation(start_val) {
execute_whatever_you_want;
};
$('#calendar').change(function() {
value = $(this).val()
yourCalculation(value);
var selectvalueds = value;
Unit_id.html('<option value="">Loading...</option>');
if (selectvalueds == '') {
Unit_id.html(initial_Unit_html);
} else {
$.ajax({
url: 'index.php',
data:'option=com_myapp&task=getUnitsHTML&dsvalue='+selectvalueds,
success: function(output) {
Unit_id.html(output);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + ' ' + thrownError);
}
});
}
});
函数计算(开始值){
执行你想要的任何事情;
};
$(“#日历”).change(函数(){
value=$(this.val()
你的计算(价值);
var selectvalueds=值;
Unit_id.html('Loading…');
如果(selectvalueds==''){
Unit_id.html(首字母为Unit_html);
}否则{
$.ajax({
url:'index.php',
数据:'option=com\u myapp&task=getUnitsHTML&dsvalue='+selectvalueds,
成功:功能(输出){
单位id.html(输出);
},
错误:函数(xhr、ajaxOptions、thrownError){
警报(xhr.status+“”+thrownError);
}
});
}
});
这将首先获取值,执行计算函数,然后添加加载选项,检查值是否为空,如果值不为空,则启动Ajax调用。您正在将2个更改事件绑定到#日历。相反,请尝试以下方法:
function yourCalculation(start_val) {
execute_whatever_you_want;
};
$('#calendar').change(function() {
value = $(this).val()
yourCalculation(value);
var selectvalueds = value;
Unit_id.html('<option value="">Loading...</option>');
if (selectvalueds == '') {
Unit_id.html(initial_Unit_html);
} else {
$.ajax({
url: 'index.php',
data:'option=com_myapp&task=getUnitsHTML&dsvalue='+selectvalueds,
success: function(output) {
Unit_id.html(output);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + ' ' + thrownError);
}
});
}
});
函数计算(开始值){
执行你想要的任何事情;
};
$(“#日历”).change(函数(){
value=$(this.val()
你的计算(价值);
var selectvalueds=值;
Unit_id.html('Loading…');
如果(selectvalueds==''){
Unit_id.html(首字母为Unit_html);
}否则{
$.ajax({
url:'index.php',
数据:'option=com\u myapp&task=getUnitsHTML&dsvalue='+selectvalueds,
成功:功能(输出){
单位id.html(输出);
},
错误:函数(xhr、ajaxOptions、thrownError){
警报(xhr.status+“”+thrownError);
}
});
}
});
这将首先获取值,执行计算函数,然后添加加载选项,检查值是否为空,如果为空,则启动Ajax调用