function retrieveHasilRawatJalan(row, kd_klp) {
var hasil_rawat_jalan2 = <?php echo
Modules::run("lab/get_row_content_from_lab_code","HL-024") ?>;
}
how to replace "HL-024" with variable kd_klp?的JavaScript和PHP:如果我使用這種方式</p> <pre><code>function retrieveHasilRawatJalan(row, kd_klp) { var hasil_rawat_jalan2 = <?php echo Modules::run("lab/get_row_content_from_lab_code",?>kd_klp<?php) ?>; } </code></pre> <p>錯誤說解析錯誤如何應用PHP標籤
內javascript變量我得到一個錯誤:語法錯誤,意外「? >」
,如果我的心不是問題不清楚,請你謝謝^^
UPDATE
之前添加AJAX
/**
*
* @param {type} id
* @returns {undefined}
*/
function retrieveHasilRawatJalan(row) {
var hasil_rawat_jalan2 = <? php echo Modules::run("lab/get_row_content_from_lab_code", "HL-003") ?> ;
//var hasil_rawat_jalan2 = <?php //echo Modules::run("lab/get_row_content_from_lab_code", row) ?>;
var number_of_row = parseInt(Object.size(hasil_rawat_jalan2));
var row_start = parseInt(row);
addNewRow(number_of_row);
var row_end = (number_of_row + row_start);
j = 1;
for (i = row_start; i <= row_end; i++) {
document.getElementById('SUBKLP[' + i + ']').value = hasil_rawat_jalan2[j]['sub_klp'];
document.getElementById('NAMA[' + i + ']').value = hasil_rawat_jalan2[j]['name_of_inspection'];
document.getElementById('KODE[' + i + ']').value = hasil_rawat_jalan2[j]['inspection_id'];
document.getElementById('HASIL[' + i + ']').value = hasil_rawat_jalan2[j]['result'];
//document.getElementById('NILAI_NORMAL[' + i + ']').value = hasil_rawat_jalan2[j]['normal_result'];
document.getElementById('NILAI_NORMAL[' + i + ']').value = 'null';
document.getElementById('SATUAN[' + i + ']').value = hasil_rawat_jalan2[j]['measure_unit'];
document.getElementById('KDKLP[' + i + ']').value = hasil_rawat_jalan2[j]['klp_id'];
j++;
}
console.log("row start: " + row_start + ", row end:" + row_end + ", column length: " + number_of_row);
}
添加AJAX
/**
* test ajax
* @param {type} row
* @returns {undefined}
*/
function retrieveHasilRawatJalan2() {
var row = "HL-003";
var hasil_rawat_jalan2;
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
//document.getElementById("demo").innerHTML = xhttp.responseText; //to print on <p id="demo"></p>
hasil_rawat_jalan2 = xhttp.responseText;
}
}
//this isnt work
xhttp.open("POST", "<?php echo site_url("
lab/get_row_content_from_lab_code/") ?>" + row, true);
//this work
xhttp.open("POST", "<?php echo site_url("
lab/get_row_content_from_lab_code /HL-003") ?>", true);
xhttp.send();
var number_of_row = parseInt(Object.size(JSON.parse(hasil_rawat_jalan2))); //try to change hasil_rawat_jalan2 to json but fail.
var row_start = parseInt(row);
addNewRow(number_of_row);
var row_end = (number_of_row + row_start);
j = 1;
for (i = row_start; i <= row_end; i++) {
document.getElementById('SUBKLP[' + i + ']').value = hasil_rawat_jalan2[j]['sub_klp'];
document.getElementById('NAMA[' + i + ']').value = hasil_rawat_jalan2[j]['name_of_inspection'];
document.getElementById('KODE[' + i + ']').value = hasil_rawat_jalan2[j]['inspection_id'];
document.getElementById('HASIL[' + i + ']').value = hasil_rawat_jalan2[j]['result'];
//document.getElementById('NILAI_NORMAL[' + i + ']').value = hasil_rawat_jalan2[j]['normal_result'];
document.getElementById('NILAI_NORMAL[' + i + ']').value = 'null';
document.getElementById('SATUAN[' + i + ']').value = hasil_rawat_jalan2[j]['measure_unit'];
document.getElementById('KDKLP[' + i + ']').value = hasil_rawat_jalan2[j]['klp_id'];
j++;
}
console.log("row start: " + row_start + ", row end:" + row_end + ", column length: " + number_of_row);
}
問題,
- 我分配
var row = "HL-003";
但我不是能夠可變行分配給xhttp.open("POST", "<?php echo site_url(" lab/get_row_content_from_lab_code/") ?>" + row, true);
除非我直接寫像這樣xhttp.open("POST", "<?php echo site_url(" lab/get_row_content_from_lab_code /HL-003") ?>", true);
- 我從
xhttp.open("POST", "<?php echo site_url(" lab/get_row_content_from_lab_code /HL-003") ?>", true);
得到的結果,但它返回的字符串不反對eventhough字符串的格式是相同的。所以我改變hasil_rawat_jalan2 = xhttp.responseText;
並添加JSON.parse(hasil_rawat_jalan2); //try to change hasil_rawat_jalan2 to object but fail.
這是否通過文件PHP解析器運行?如果這只是簡單的js交付給客戶端的PHP代碼將不會被執行。 – m02ph3u5