Reputation: 353
I want this div displayed on my page whenever there is a "Y" in the database.
<div style="width:100%; height:41px; position:fixed; bottom:0px; background:#184888; padding:22px 0 0 15px; bottom:0px; z-index:9997; box-shadow: 10px 10px 5px #888888;" id="hide">
<div id="message" style="z-index:9998;"> </div>
How would I make it so that the div is displayed and not displayed without refreshing the page. Basically I have to see if it is a "Y" in the database, and if it is, display the div. If an "N" is in the database do not display the div, using JavaScript.
I am currently using this function to see check the database for a value.
$('div#checkcheck').load('../bar/check.php/check.php');
Upvotes: 0
Views: 72
Reputation: 1249
Try this:
$.getJSON('../bar/check.php/check.php', function(res){
if(res === 'Y')
{
$('div').show();
}
else
{
$('div').hide();
}
});
Upvotes: 0
Reputation: 15213
$.get('../bar/check.php/check.php', function(response) {
$('div#checkcheck')[response === 'Y' ? 'show' : 'hide']();
});
Upvotes: 0
Reputation:
Pass an anonymous function to your jQuery load. This will be able to catch the value from check.php
$('div#checkcheck').load('../bar/check.php/check.php', function(response) {
//do something with that response
});
Upvotes: 2
Reputation: 2163
Send an ajax request to your server. Let your php code check for the 'Y' in database. Your server call will return a json.
Use that json in javascript to check for 'Y' or'N' and then show/hide your div.
Upvotes: 0