I am aware that I can call PHP scripts after processing an AJAX request, but am I able to do it the other way around?
I am writing a dynamically sized navigation component for a new website and I want to refresh the nav every time a new item is added to the Menu.
In my menu class I am currently thinking of using this approach to achieve the effect:
public static function new_item($label, $link) {
$pos = self::num_items();
$DB = Database::getInstance();
$query = $DB->connection->prepare("INSERT INTO menu VALUES('', :label, :link, :pos )");
$query->execute(array(':label'=>$label,
':link' =>$link,
':pos' =>$pos+=1
));
?>
<script>
function refreshHeader() {
$.ajax({
type: "GET",
url: "my url",
success: function() {
// refresh the header here somehow
}
});
}
</script>
<?php
}
However, every time this runs I see nothing in my console (even when I put a valid url into my function), will I be able to achieve what I want this way or would I be better processing appending the tab to the document via AJAX and then calling the insert method in my Menu class on the success callback?
The only reason I ask is I feel this way may look neater in comparison to the other way of handling it, although I may be completely wrong.
Any feedback would be greatly appreciated - cheers Alex.