PHP 페이지 내에 서블릿로드가 있습니다. 여기는 내 PHP 페이지입니다. reviewing.php
if(isset($_GET['x'])){
$x = $_GET['x'];
}else{
$x = '';
}
$site = $_SERVER['SERVER_NAME'];
if(isset($_GET['id'])){
$Id = "id=".$_GET['id'];
}else{
$Id = "";
}
$handle = fopen("http://".$site.":8080/Apps/reviewing.php?$Id", "r");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
echo $contents;
보시다시피 내 PHP 페이지가 서블릿을로드합니다. 서블릿은 프로세스가 발생하는 곳입니다. 서블릿에 JSP 및 html 페이지도 포함됩니다.
다른 드롭 다운의 옵션이 변경된 경우 드롭 다운의 값을 변경할 수 있어야합니다. 둘 다 별도의 mysql 쿼리이지만 드롭 다운이 변경된 경우에만 두 번째 쿼리를 실행해야합니다. 이 작업을 수행하는 이유 WHERE
는 dropdown2 쿼리에서 와 같이 dropdown1 값을 사용할 수 있기 때문 입니다.
나는 같은 것을 시도했다
function reload(form)
{
var ID = form.agent.options[form.agent.options.selectedIndex].value;
return ID;
}
이 기능은 <select onchange="reload(this.form);">
다음 쿼리를 실행하기 위해 ID를 사용하고 싶습니다.
<select>
//javascript
if(isset(reload())){
//JAVA
run query here WHERE id = ID;
while(rs.next()){
outn.print("<option>" + rs.getString("value") + "</option>");
}
}
</select>
그게 내가 상상하는 방법입니다. 다른 옵션은 reload () 함수에서 이것을 사용하는 것입니다.
self.location='http://exmaple.com/reviewing.php?x=blah&ID=blah;
하지만 페이지를 계속 새로 고침 할 필요는 없습니다. 비효율적입니다.
좋아, 따라서 다음과 같이 프로그램을 작성해야합니다.
선택 요소 onchange 이벤트 처리
이 핸들러에서 선택한 인덱스를 얻을 수 있습니다.
다음은 간단한 코드 예입니다.
HTML
<select id='select1'>
<option id='option_1' value='1'>Option 1</option>
<option id='option_2' value='2'>Option 2</option>
<option id='option_3' value='3'>Option 3</option>
<option id='option_4' value='4'>Option 4</option>
</select>
<select id='select2'>
</select>
JS
document.getElementById('select1').onchange = function(){
var xmlhttp=new XMLHttpRequest();
var params = "id="+this.value //you can add more data, use & as delemitter
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
fillSelect(xmlhttp.responseText);
}
}
xmlhttp.open("POST","path/to/php.php",true);
xmlhttp.send(params);
}
var fillSelect = function(response){
//Here you can go through all elements from response
//and build new options and append them to Select2
}
PHP
if (!isset($_POST('id')) die("Submission failed!");
$id = $_POST('id');
$mysqli = new mysqli(HOST, USER, PW, DB); //assuming you have these static variables, change it for your settings
//use $id now to create the query
$query = "[...]";
$result = $mysqli->query($query);
echo json_encode($result);
PHP에 실수가 없기를 바랍니다. 나는 그것을 시험 할 수 없었다. 뭔가 잘못된 경우 철자가 올바른지 확인하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다