TheNewDude
New member
This works when I run the code using just php, but it is inefficient. I figured ajax could help me. But I am new to ajax and javascript and I really don't know much about it. I was able to find a tutorial on w3schools that I was able to use to create some javascript code to fit my purposes. I am pretty sure the javascript code is correct. So I figure that maybe there are certain things that can't be returned via ajax. Could somebody tell me if the following code can be returned via ajax? If it cannot be, is there any way around it?
function get_selectable_categories() {
$categories = get_all_categories();
while($category = mysql_fetch_assoc($categories)) {
echo "<option value=" . $category['id'] . "";
echo ">" . $category['cat_name']. "</option>";
}
}
function get_all_categories() {
global $connection;
$query = "SELECT *
FROM categories
WHERE visible = 1
ORDER BY cat_name ASC";
$category_set = mysql_query($query, $connection);
confirm_query($category_set);
return $category_set;
}
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
In case you are wondering, I am having the returned information placed between <select></select> tags.
Yes, it is set to responseText. Here is the line from the js page. The select tags have been given an id of categories.
document.getElementById("categories").innerHTML=xhr.responseText;
Yes, it is set to responseText. Here is the line from the js page. The select tags have been given an id of categories.
document.getElementById("categories").innerHTML=xhr.responseText;
I just checked to see if the request is going to the correct page using an alert an it is going to the correct page. I just can't get anything from that page.
function get_selectable_categories() {
$categories = get_all_categories();
while($category = mysql_fetch_assoc($categories)) {
echo "<option value=" . $category['id'] . "";
echo ">" . $category['cat_name']. "</option>";
}
}
function get_all_categories() {
global $connection;
$query = "SELECT *
FROM categories
WHERE visible = 1
ORDER BY cat_name ASC";
$category_set = mysql_query($query, $connection);
confirm_query($category_set);
return $category_set;
}
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
In case you are wondering, I am having the returned information placed between <select></select> tags.
Yes, it is set to responseText. Here is the line from the js page. The select tags have been given an id of categories.
document.getElementById("categories").innerHTML=xhr.responseText;
Yes, it is set to responseText. Here is the line from the js page. The select tags have been given an id of categories.
document.getElementById("categories").innerHTML=xhr.responseText;
I just checked to see if the request is going to the correct page using an alert an it is going to the correct page. I just can't get anything from that page.