Javascript Ajax-为php填充多个文本框
我有一个带有下拉菜单的html页面,该菜单有效,onchange调用了一个同样有效的函数popBox()。在这个函数中,我使用ajax将下拉菜单的值发布到php中,在php中选择db。我希望在“DetailsForm”表格的文本框中填入所选信息。我目前没有填写任何文本框,并且警报(msg)在和警报框中显示页面的整个html端。有人能帮我解决这个问题吗。我尝试了ajax和jquery的多种不同变体来执行此操作,15小时后,在同一个函数上,至少可以说,我开始有点沮丧。提前谢谢你的帮助,我非常感激 这是我的密码: HTMLJavascript Ajax-为php填充多个文本框,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我有一个带有下拉菜单的html页面,该菜单有效,onchange调用了一个同样有效的函数popBox()。在这个函数中,我使用ajax将下拉菜单的值发布到php中,在php中选择db。我希望在“DetailsForm”表格的文本框中填入所选信息。我目前没有填写任何文本框,并且警报(msg)在和警报框中显示页面的整个html端。有人能帮我解决这个问题吗。我尝试了ajax和jquery的多种不同变体来执行此操作,15小时后,在同一个函数上,至少可以说,我开始有点沮丧。提前谢谢你的帮助,我非常感激 这
旅行
函数popBox(str)
{
$.ajax({
键入:“PopulateBoxes.php”,
数据:{dat:str}
}).done(函数(msg){//您也可以使用success
警报(“保存的数据:“+msg”);
});
//document.getElementById(“txt_Duration”).value=;
//document.getElementById(“txt_船只名称”).value=;
//document.getElementById(“txt_位置”).value=;
//document.getElementById(“txt_可用”).value=;
//document.getElementById(“txt_价格”).value=;
}
旅行
选择旅游详情
请选择
尝试修改类似以下内容的JS代码:
function popBox(selectValue) {
$.ajax({
type: 'POST',
url: "PopulateBoxes.php",
data: { dat: selectedValue },
success: function(serverResponse) {
// after success request server should return response with data
// that will be passed to this callback function as parameter
// and you can use it to fill text boxes:
$('#txt_Duration').val(serverResponse.duration);
}
});
}
您还应该修改PHP代码以返回JSON格式的数据:
// At the end you should return selected array. For example:
echo json_encode($dataArray); exit;
尝试修改类似以下内容的JS代码:
function popBox(selectValue) {
$.ajax({
type: 'POST',
url: "PopulateBoxes.php",
data: { dat: selectedValue },
success: function(serverResponse) {
// after success request server should return response with data
// that will be passed to this callback function as parameter
// and you can use it to fill text boxes:
$('#txt_Duration').val(serverResponse.duration);
}
});
}
您还应该修改PHP代码以返回JSON格式的数据:
// At the end you should return selected array. For example:
echo json_encode($dataArray); exit;
在PHP代码中使用$\u POST时,需要编辑ajax调用脚本。 类型为GET或POST,页面地址进入url属性
$.ajax({
type: 'POST',
url: "PopulateBoxes.php",
data: { dat: str}
}).done(function( msg ) { //you can also use success
alert( "Data Saved: " + msg );
});
}
在PHP代码中使用$\u POST时,需要编辑ajax调用脚本。 类型为GET或POST,页面地址进入url属性
$.ajax({
type: 'POST',
url: "PopulateBoxes.php",
data: { dat: str}
}).done(function( msg ) { //you can also use success
alert( "Data Saved: " + msg );
});
}