长篇故事:
我有两个php页面,
在start.php页面中,我有一个选择下拉列表:
<select name="patient-list" id="patient-list" onchange="getPatientInfo(this.value)"></select>
我使用jquery ajax填充patient_list.xml中的患者姓名和详细信息:
$.ajax({
type:"GET",
url:"./content/patient_list.xml",
dataType:"xml",
success: function(xml) {
$('patient', xml).each(function(){
var patient_id = $(this).attr('value');
var first_name = $(this).children("first_name").text();
var last_name = $(this).children("last_name").text();
var patient_name = first_name + " " + last_name;
$("#patient-list").append("<option class='patient' value='" + patient_id + "'>"+patient_name+"</option>");
//by default, the first item in patient_list.xml will show up
if (patient_id == 1) {
$(this).children().each(function(){
t = this.tagName;
addPatientDetails.call(this, t);
});
}
});
}
});
addPatientDetails是这样的:
function addPatientDetails (tagName) {
var tag = $(this).text();
var t = tagName.replace(/_/g, ' ');
var detailTitle = t.replace(/\w\S*/g, function(t){return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase();});
$("#patient_" + tagName).html("<p><span class='detail-title'>" + detailTitle + ": </span>" + tag + "</p>");
}
和onchange getPatientInfo是这样的:
function getPatientInfo (patientID) {
$.ajax ({
type: "GET",
url: "./content/patient_list.xml",
dataType:"xml",
success: function (xml) {
$(xml).find("patient[value=" + patientID + "]").each(function(){
$(this).children().each(function(){
nm = this.tagName;
console.log(nm);
addPatientDetails.call(this,nm);
});
});
}
});
}
现在我有第二个php页面patient_session.php。我想实现:
当有人从start.php页面中选择患者时,患者姓名将在patient_session.php中显示/更改。
实现这一目标的最有效方法是什么?
非常感谢!