Hallo Leute ich zerbrech mir schon ein paar Stunden den Kopf und finde einfach nicht den Fehler. ich bin aber auch nicht so fit was Ajax und co betrifft vielleicht kann jemand helfen?
Source von fill.php
Sourcecode von Index.php:
dann habe ich noch eine conn.php aber hier stehen nur die reinen Login Daten für den MS-SQL Server
Das Skript scheint es nicht hinzubkekommen die fill.php zu durchlaufen denn ich bekomme weder eine Fehlermeldung im Menu City noch eine anderen Eintrag das Menü ist einfach leer
Source von fill.php
PHP-Code:
<?php
include 'conn.php';
if(isset($_POST['code']))
{
$SQL = "SELECT * FROM test.dbo.city WHERE CountryCode = '".$_POST['code']."'";
//print_r($_POST['code']);
$query = sqlsrv_query($conn,$SQL);
/*
if (sqlsrv_num_rows($query) === false)
echo '<option >Keine Datensätze gefunden </option>';
} else{
*/
while ($row = sqlsrv_fetch_array($query)){
$res = "<option ";
$res .= "value'". $row['ID'] . "' >";
$res .= $row['Name'];
$res .= "</option>";
echo $res;
}
}
} else {
echo'<option>error</option>';
}
?>
PHP-Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Fill Select using TSQL, PHP, JQUERY AJAX</title>
<script src="jquery-1.11.1.min.js"></script>
<!--<script src="http://code.jquery.com/jquery-latest.js"></script> -->
<script>
$(document).ready(function(){
$('#cnt').change(function(){
var code = $(this).val();
//alert(code); //testing
var data = 'code='+code;
alert(code); //testing
$.ajax({
type : "POST",
url : "fill.php",
data : data,
cache : false,
success : function(html)
{
$('#city').html(html);
}
});
});
});
</script>
</head>
<body>
<form method"POST">
<select name="cnt" id="cnt">
<?php
include 'conn.php';
$SQL = "SELECT * FROM test.dbo.country";
$query = sqlsrv_query($conn,$SQL);
while ($row = sqlsrv_fetch_array($query))
{
$res = "<option ";
$res .= "value'".$row['Code']."'>";
$res .= $row['Name'];
$res .= '</option>';
echo $res;
}
?>
</select>
<br/>
<select name"city" id="city">
<option selected="selected">City go here </option>
</select>
</body>
</html>
Das Skript scheint es nicht hinzubkekommen die fill.php zu durchlaufen denn ich bekomme weder eine Fehlermeldung im Menu City noch eine anderen Eintrag das Menü ist einfach leer
Kommentar