How to dynamically load Content in Div with Jquery? (Code given) - javascript

I want to have a overlay over my content site. So if somebody clicks on a link a article is loaded into the covering overlay Div
Everything is working fine except the output is not working properly.
<script language="javascript">
$( ".iddd" ).click(function() {
var aid = $(this).prop('id');
$('#overlaycontent').load('http://www.example.com/overlay.php', { id: aid });
});
Test PHP Script:
<?php
include ("config.php");
$ID = $_POST['id'];
echo $ID;
?>
That´s how my links are placed:
<a class="iddd" href="#overlay" id="6337cab172">
The id should be loaded into the script so I can access my articles but i guess the Jquery is not working properly.
I looked at this overlay with dynamic php content the right way?
but still it doesnt post the ID properly!

Not sure what is in config.php and if missing that could cause your problem, but to include a file, you don't use parenthesis, but only quotes, so, instead of
include ("config.php");
just
include "config.php";

Related

The div content script problem on the other page when the button is pressed

$("#maincont<?php echo $forwardInterviews; ?>").load("/xx/xx/xx/xx/xx/buttonClickDetails.php",
When the button is pressed, I bring the content. JSs are missing when fetching the content. JSs appear in the footer in the source code. But the selectpicker property in buttonClickDetails.php does not work.
When I include buttonClickDetails.php as below, selectpicker does not work.
<script src="<?php echo url()."assets/js/bootstrap-select.min.js"; ?>"></script>
I was using the selecpicker class in the div that I called with Ajax. But since I did not renew the selecpicker after calling it, the script was not working.
$('.selectpicker').selectpicker('refresh');
My problem was solved with the code.

External php file that is loaded into index.php with .load() method not recognising $_SESSION variables

So my main page loads other php pages into it with click of a button so it can be a single page website without having to load all the content at once.
index.php
<?php
session_start();
?>
<head>
$('#btnPetShop').one( "click", function(){
$( "#page_shop" ).load( "shop.php" );
});
</head>
<body>
<?php
echo session_status();/----Always returns 1, no matter if logged in or not----/
if(isset($_SESSION['admin']))
{
if($_SESSION['admin']==1)
{
/----this part works, I am logged in as admin----/
}
}
?>
<div id="page_shop"></div>
</body>
shop.php
<?php
if(isset($_SESSION['admin']))
{
if($_SESSION['admin']==1)
{
}
else{}
}
else{} <----I end up here as if $_SESSION['admin'] is not set----/
/----code entered here loads fine----/
?>
The idea is to make a delete and edit button (if you are logged in as admin) on every article in shop.php.
Problem is that $_SESSION['admin'] is recognized on index.php, but not inside shop.php
I tried typing the content of shop.php directly into and it works, the problem is that i want it to load with a click of a button.
Where ever ( in any PHP page) if you want to use any Session variable then you have to first declare session_start(); so, in your case if you have $_SESSION['admin']="User1234" on index.php and if you want to use value of $_SESSION['admin'] in shop.php then you have to again declare session_satart(); and then use it. For example, If let consider that index.php has session variable $_SESSION['admin']="User1234" and now you want to print "Welcome User1234" on shop.php then you can do it as shown below.
index.php
<?php
session_start();
$_SESSION['admin'] = "User1234";
?>
Shop.php
<?php
session_start();
echo "Welcome, ". $_SESSION['admin']
?>
Output:
Welcome, User1234
You need to add session_start(); in each page that needs access to the session data.
See: http://php.net/manual/en/function.session-start.php
EDIT
Since the solution mentioned in my original answer does not work for you and session_status() returns 1 in your code, it means sessions are enabled on your server. There is only one thing left which could explain that your sessions are lost:
You are loading shop.php with an AJAX request, is the URL exactly in the same domain as index.php? Try to add the full path before shop.php to see if this solves the issue.
Just to be clear, if your index.php runs on http://localhost/test/index.php, your new code will be:
$( "#page_shop" ).load( "http://localhost/test/shop.php" );
Well okay, I feel dumb... I found the solution.
I had this as a script
$('#btn_logout').click(function(){
<?php session_destroy();?>
});
This is a big no no and if you do this you should be ashamed

.load() function won't load javascript

When I use the function .load(), it will load the page that I want to load in the div that is selected.
But when I want to use JavaScript/jQuery that I already have coded in other files, it wont work anymore.
It does work when I just include ''; the page static in the div.
Does anyone have an idea why this works like this?
Static:
<div id="loginCont" class="modal-body">
<?php
include 'login.php';
?>
</div>
by Javascript/jQuery
$("#memberFalse").on("click", function() {
$('#loginCont').load("/213server/_inc/login.php");
});
A PHP include that starts with "/" refers to the root of the server, unless specified otherwise in your php.ini file. Your code:
<div id="loginCont" class="modal-body">
<?php
include 'login.php';
?>
</div>
fetches "login.php" from the folder where the current page is located. You can display that location with:
<?php echo __DIR__ ?>
Your jQuery load() method should fetch the page "login.php" from that location too. There is obviously a mistake in the following path:
$('#loginCont').load("/213server/_inc/login.php");
Remember that Javascript/jQuery CANNOT fetch files outside the web root, but PHP can. For example, if your login.php file is located at "/var/_inc/login.php" and your web root is at "/var/www/", jQuery will never have access to login.php. If your login.php file is located at "/var/www/myproject/_inc/login.php", then your load() function should fetch it like this:
$('#loginCont').load("/myproject/_inc/login.php");

Unearthing a js php load/execution issue

Running a base web framework from https://github.com/panique/huge/
The overarching problem I have is: html table needing live updates to account for database (mysql) changes.
Where I'm stuck: I have added to the index/index.php page, the following javascript code to the end of the file (note: header and footers loaded around this index/index.php page) in attempt to refresh the need for updating the table every few seconds in order reload the html table based off of the mysql database state. The index/tableChange module simply gathers the mysql data and returns the query.
<?php echo "
<script language='javascript' type='text/javascript'>
function loadlnk() {
document.getElementById('tableHolder').innerHTML =
\"<object type=\"text/html\" data=\"<?php echo config::get('URL'); ?>index/tableChange\"></object>\";
setTimeout(loadlnk, 3000);
}
loadlnk();
</script>";
?>
When I test the index/tableChange snippet out, I am able to load the php by itself in its own individual webpage (but for the purpose of this question, I'm needing to load that content of tableChange into the index/index page).
I also tried adding the $(document).ready(function() { around inside of the script, but this didn't seem to help accomplish anything visible to changing the table.
I looked at what I understood and could find, but I don't think it's a quote issue.
You might like to remove the inner PHP tags and the echo statement and try like this:
<?php
echo "
<script language='javascript' type='text/javascript'>
function loadlnk() {
document.getElementById('tableHolder').innerHTML =
\"<object type=\"text/html\" data=\"" . config::get('URL') ."index/tableChange\"></object>\";
setTimeout(loadlnk, 3000);
}
loadlnk();
</script>";
?>
I found that I was getting an error in the console, similar to the following:
Load denied by X-Frame-Options: https://localhost/test/target.php does
not permit framing.
The solution, at least a quick one in this instance was to add a header before sending the output from /test/target.php ~ name header('X-Frame-Options: sameorigin'); then it worked just fine.

Woocommerce All JS And Jquery elements are not loading

I had made my theme to be compatible with woocommerce, by creating woocommerce.php, and adding a custom function in my functions.php file which is
add_theme_support( 'woocommerce' );
And this is how my woocommerce.php file looks like :
<?php
global $mandigo_options, $dirs;
get_header();
// heading level for page title (h1, h2, div, ...)
$tag_post_title_single = $mandigo_options['heading_level_post_title_single'];
?>
<td id="content" class="<?php echo ($mandigo_options['sidebar_always_show'] ? 'narrow' : 'wide'); ?>column"<?php if (mandigo_sidebox_conditions($single = true)) { ?> rowspan="2"<?php } ?>>
<div class="woocommerce">
<?php woocommerce_content(); ?>
</div>
</td>
<?php
// if we have at least one sidebar to display
if ($mandigo_options['sidebar_always_show'] && $mandigo_options['sidebar_count']) {
if (mandigo_sidebox_conditions($single = true))
include (TEMPLATEPATH . '/sidebox.php');
include (TEMPLATEPATH . '/sidebar.php');
// if this is a 3-column layout
if ($mandigo_options['layout_width'] == 1024 && $mandigo_options['sidebar_count'] == 2)
include (TEMPLATEPATH . '/sidebar2.php');
}
get_footer();
?>
Everything is appearing fine now, but I can't find the add to cart button and also all the elements that uses javascript or jquery are not loading.
I had tried :
To use wordpress JQuery updater
To put the jquery library reference in the header.php
Deactivating all plugins
I had all the fields of the necessary elements in woocommerce field like the price, but its obvious that this is a JS or JQuery error.
And here is a link to the site is product page :
http://www.doctor-detail.com/product/gift-card-product-2
Any help would be much appreciated!
When I inspected the site and checked the console I found that although I was linking to the latest jquery in the header of my site, it was using the main jquery of the theme.
So, all I needed to do is to remove the theme is Jquery file from the JS folder.
After that woocommerce was working fine.
You should use wp_enqueue_script() in functions.php instead of linking in a header.php, Plese keep in mind JQuery in enqueued by default. If you need to change version, fist you have to deregister the default one.

Categories

Resources