Hi all, wonder if anyone has a moment, trying to create a dynamic dropbox that is populated from the selection of an original dropbox using ajax ( i know this part is working because the secondary dropbox alters with no data as soon as the original “customerID” box is altered, this seems to be very problematic because my “bootstrapper” which inspects the URL for the MVC models/functions is picking up the ajax request and basically saying it doesnt exist, if anyone could point me in the rite direction that would be great.
the contactSelect.php page that the ajax calls –
[code=php]<?php
$customerID = $_POST[‘customerID’];
$conn2 = new mysqli(DB_HOST,DB_USER, DB_PASS, DB_NAME)
or die (‘Cannot connect to db’);
$result2 = $conn2->query(“SELECT * FROM contacts where CustomerID=”.$customerID);
while ($row = $result2->fetch_assoc()) {
?>
<option value=”<?php echo $row[‘ContactID’]; ?>”><?php echo $row[‘ContactName’]; ?></option>
<?php
}
?>
the ajax request that index.tpl calls when the customerID dropbox selection is altered
[CODE] <script type=”text/javascript”>
$(document).ready(function(){
$(“#customerID”).change(function(){
var customerID = $(“#customerID”).val();
$.ajax({
type:”post”,
url:”contactSelect.php”,
data:”customerID=”+customerID,
success: function(data) {
$(“#contactDrop”).html(data);
}
});
});
});
</script>
The original selection drop down also in index.tpl
[code=php] <select name=”customerID” id=”customerID” >
<?php
$conn = new mysqli(DB_HOST,DB_USER, DB_PASS, DB_NAME)
or die (‘Cannot connect to db’);
$result = $conn->query(“SELECT * FROM customer”);
while ($row = $result->fetch_assoc()) {
echo ‘<option value=”‘.$row[‘customerID’].'”>’ . $row[‘customerName’] . ‘</option>’;
}
?>
</select>
The bootstrapper page which controlls the MVC flow
[code=php]<?php
$controller = “contact”;
$action = “index”;
$query = null;
if (isset($_GET[‘load’]))
{
$params = array();
$params = explode(“/”, $_GET[‘load’]);
$controller = ucwords($params[0]);
if (isset($params[1]) && !empty($params[1]))
{
$action = $params[1];
}
if (isset($params[2]) && !empty($params[2]))
{
$query = $params[2];
}
}
$modelName = $controller;
$controller .= ‘Controller’;
$load = new $controller($modelName, $action);
if(!empty($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’)
{ //some sort of direct call to the php page should be created here because its an ajax request }
else
{
if (method_exists($load, $action))
{
$load->{$action}($query);
}
else
{
//die(‘Invalid method. Please check the URL. Action is: ‘.$action.’ and query is ‘.$query);
$load->{$action}($query);
}}
IE9 dev tools states that: <br />
<b>Fatal error</b>: Call to undefined method ticketcontroller::contactSelect.php() in <b>C:inetpubmvcutilitiesbootstrap.php</b> on line <b>39</b><br />
so my understanding is that the MVC is trying to pickup the ajax request, i put it a condition which checks if its an ajax but I dont know how best to handle the action, sorry this is so long winded, thanks alot in advance.