Is it possible to return javascript function via Ajax from php? Normally I would just return a value then decide what to do with it in plain javascript, but now because I am handling Apache Cordova mobile app I want to do things differently.
account = localStorage.getItem("account");
account = JSON.parse(account);
$.ajax({
type: "POST",
url: example.php,
data: { account = account.rule }
});
.php
$isAdmin = $conn->prepare("SELECT role FROM users WHERE username = :username");
$isAdmin->bindParam(":username", $username);
$isAdmin->execute();
$result = $isAdmin->fetch(PDO::FETCH_ASSOC);
if($result){
$result = "<script>
$("header nav").append(
$("<a />").attr("href", "admin.html").text("Admin panel")
)
</script>";
}
return $result;
And then run it. Ill do another check when user redirects to the site.