Content added by load() function dissapears after ajax action - php

I am creating a sorting page, which will show content of database, and the user can sort it with listjs. Problem is that when i press any button, the content loaded from the database disappears. When I fill the content manually it works great. Can anybody please help me with this problem?
My load function:
$(document).ready(function(){
$(".list").load("../wp-content/php/sorting.php");
});
sorting.php
<?php
mysql_connect("***", "***", "**") or die(mysql_error());
mysql_select_db("***");
$result = mysql_query("SELECT * FROM business");
while($row = mysql_fetch_array($result))
{
?><li class="onebusiness"><a href="<?php
echo $row['link'];?>"><img src="<?php
echo $row['img'];?>" height="125" width="125"/><p class="name"><?php
echo $row['name'];?></p><p class="category" style="display:none;"><?php
echo $row['category'];?></p></a></li><?php
}
mysql_close();
?>
HTML:
<script src="../wp-content/js/filter/call-php.js" type="text/javascript"></script>
<script src="../wp-content/js/list/list-min.js" type="text/javascript"></script>
<div id="busineseslist">
<input class="search" placeholder="Search Business" />
<ul class="sort-by">
<li class="sort btn" data-sort="name">Sort by name</li>
<li class="sort btn" data-sort="category">Sort by category</li>
</ul>
<ul class="filter">
<li class="btn" id="filter-none">Show all</li>
<li class="btn" id="filter-something">Only show something</li>
<li class="btn" id="filter-else">Only show something else</li>
</ul>
<div class="list"></div>
</div>

Why you dont just do this:
<script src="../wp-content/js/filter/call-php.js" type="text/javascript"></script>
<script src="../wp-content/js/list/list-min.js" type="text/javascript"></script>
<div id="busineseslist">
<input class="search" placeholder="Search Business" />
<ul class="sort-by">
<li class="sort btn" data-sort="name">Sort by name</li>
<li class="sort btn" data-sort="category">Sort by category</li>
</ul>
<ul class="filter">
<li class="btn" id="filter-none">Show all</li>
<li class="btn" id="filter-something">Only show something</li>
<li class="btn" id="filter-else">Only show something else</li>
</ul>
<div class="list"><?php include '../wp-content/php/sorting.php'; ?></div>
</div>
With this you can delete this line:
<script src="../wp-content/js/filter/call-php.js" type="text/javascript"></script>//delete this
Which i think its the js with the following code:
$(document).ready(function(){
$(".list").load("../wp-content/php/sorting.php");
});
Because with the php include you dont need the load function ;)
------------------------EDITED----------------------------------------
In wordpress, you can include files in this way:
Put the include files in your theme folder and use this in your theme's footer.php:
<?php include (TEMPLATEPATH . '/sorting.php'); ?>
See this reference link: http://www.deluxeblogtips.com/2010/06/wordpress-include-template-files.html
Your div should looks like:
Go to the 'Theme Editor', look for the file that generates the html. Edit it and place this code between the divs tags:
<div class="list"><?php include (TEMPLATEPATH . '/sorting.php'); ?></div>
Saludos.

Related

PDO I can't get the title to show in the select tag from a query made in php

I'm trying to get the select tag to show the titles of the posts that are in the DB so i can select them individually and up date them instead of updating all the titles with the same name.
So my problem is that i can't get it to work and maybe someone may be able to help me.
This is what i mean->https://imgur.com/a/ie1g4hF
if you want the full version you can get it from my github:
https://github.com/TwistedZebra/blog
That version up there does not contain the select tags but uses a text box to delete the post that is named but with a disadvantage of deleten every post named the same.
<?php
require 'config.php';
if (isset($_POST['submit'])) {
$updatetitle = $_POST['updatetitle'];
$title = $_POST['title'];
$content = $_POST['content'];
if (empty($title) || empty($content)) {
header('Location: update.php?=error');
exit();
} else {
$updatedcontent = $connection->prepare('UPDATE posts SET title = :title , content = :content WHERE title = :updatetitle');
$updatedcontent->execute(['title' => $title, 'content'=> $content, 'updatetitle' => $updatetitle]);
header('Location: update.php?=success');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="public/css/main.css">
<title>Control panel</title>
</head>
<body>
<div class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="navbar-brand ">
<h2>BloggerWorld</h2>
</div>
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="public/index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="public/posts.php">Posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="adminpanel.php">Admin Panel</a>
</li>
</ul>
</div>
<br><br><br><br><br><br><br>
<div class="container-fluid">
<div class="container">
<h1>Update post</h1>
<form method="post" action="update.php" >
<select name="delTitle" class="form-control">
<?php foreach ($updatedcontent as $update) { ?>
<option><?php echo $post['title']; ?></option>;
<?php } ?>
</select>
<br>
<input type="text" name="title" class="form-control" placeholder="New title" >
<br>
<textarea name="content" rows="5" cols="60" class="form-control" placeholder="Enter post"></textarea>
<br>
<br>
<button type="submit" name="submit" class="btn btn-success">Update post</button>
</form>
</div>
</div>
<script>
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] +
':35729/livereload.js?snipver=1"></' + 'script>')
</script> enter code here
</body>
</html>

Page not loading after php include

I have a page which includes the menu bar (a php page). This works, but strangely the page doesn't load after the include.
Some code:
<div class="center">
<?php
include ('../menu.php')
?>
<div class="text" id="media">
Some text
</div>
When I add the
<div class="text" id="media">
Some text
</div>
to the menu.php it is showed, but not when it is on the parent page. Anybody has an idea? There isn't any warning or error showing.
<!-- begin menu -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="../../../../style/menu.css">
<div class="menu_b">
<div class="logo">
<img src="../../../../afbeeldingen/menu/logo.gif" width="375" title="Home" />
</div>
<div class="aangemeld">
</div>
<ul class="menu_tekst">
<li class="<?php echo $account_li;?>"><a class="nt" href="../../../../account.php">Account</a></li>
<li class="tussenstuk"></li>
<li class="<?php echo $contact_li;?>"><a class="nt href="../../../../contact.php">Contact</a></li>
<li class="tussenstuk"></li>
<li class="<?php echo $fotos_li;?>"><a class="nt" href="../../../../fotos.php">Foto's</a>
<ul class="sub_fotos sub">
<li class="space_left"> </li>
<li class="titel_blok_sub"><a class="nt" href="../../../../fotos/2013_2014.php">2013-2014</a></li>
<li class="titel_blok_sub"><a class="nt" href="../../../../fotos/kamp.php">Kampfoto's 2014</a></li>
</ul>
</li>
<li class="tussenstuk"></li>
<li class="nt"><a class="nt" href="../../../../winkelwagen.php">winkelwagen + besteld</a></li>
</ul>
</div>
<div class="onder_menu">
</div>
<div class="sub_menu">
</div>
<!-- einde menu -->
you forgot semicolon ;
include ('../menu.php');
You forgot a quotation mark:
<li class="<?php echo $contact_li;?>">
<a class="nt href="../../../../contact.php">Contact</a>
</li>
should be
<li class="<?php echo $contact_li;?>">
<a class="nt" href="../../../../contact.php">Contact</a>
</li>
Succes ermee
Above the div.center their was an other php include of a page that doesn't exist, after removing it, the page loaded. Didn't looked at it because it was above the menu.php which was loaded.
Try using require:
require('../menu.php');
I'm guessing that you have turned off display errors in your php.ini and that menu.php doesn't exist.
If you are not sure how to turn on error reporting in your development machine, add the following lines to your parent page;
<div class="center">
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include ('../menu.php');
?>
<div class="text" id="media">
Some text
</div>
This should then reveal why the page is not being included.
Take the parenthesis off the include statement. It should look like this:
include 'page.php';

How to add slider in the wordpress index.php file?

My javascript code for slider is as follows which is displayed in the
html format but not displayed when I integrated it into a theme.This code is in header.php.I have called all the requred js css and image files in it and that worked fine but the problem is in slider portion.
Code in header.php
<script type="text/javascript">
$(window).load(function() {
$('.flexslider').flexslider({
animation: "slide",
useCSS: Modernizr.touch
});
});
</script>
Code in index.php
<div class="flexslider">
<ul class="slides">
<li>
<div class="hero-unit">
<h1>Affordable Hosting Solution</h1>
<h3>Flathost is a bootstrap based responsive minimal, flat and afforable
hosting template with easy customization and great support</h3>
<div class="slider-actions text-center"> <a href="features.html" class="btn
btn-success btn-lg">Explore Features </a> <a href="pricing.html" class="btn
btn-primary btn-lg">Plans and Pricing </a> </div>
</div>
</li>
<li>
<div class="slide2">
<p><img src="<?php echo get_template_directory_uri(); ?
>/images/server1.png" alt="server" class="img-responsive center-block"></p>
<h1>Dedicated and VIP Hosting</h1>
</div>
</li>
<li>
<div class="slide3">
<p class="pull-left"><img src="<?php echo get_template_directory_uri(); ?
>/images/server2.png" alt="server" class="img-responsive"></p>
<h1>Managed Hosting</h1>
<h3>Flathost is a bootstrap based responsive minimal, flat and afforable
hosting template with easy customization and great support </h3>
</div>
</li>
</ul>
</div>
</div>
</div>
<?php echo do_shortcode('[thethe-image-slider name="flexslider"]'); ?>

Change class for active menu item with php

I am trying to change the class of an active element in my menu with php, but I am having trouble when using "?side=testpage" as URL
I'm typing the href in php to get the pages opened in the correct div according to my index where this code is included.
The whole code is:
<?php
function echo_Active_Tab ($requestUri){
$current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
if ($current_file_name == $requestUri)
echo 'class="active"';
}
?>
<div class="navbar">
<div class="navbar-inner">
<a class="brand"<?php echo "href='?side=mainpage'>Økonomiprogrammet</a>"; ?>
<ul class="nav">
<li <?=echo_Active_Tab("mainpage")?>><?php echo "<a href='?side=mainpage.php'>Startside</a>"; ?></li>
<li <?=echo_Active_Tab("overview")?>><?php echo "<a href='?side=overview'>Oversikten</a>"; ?> </li>
<li <?=echo_Active_Tab("invoice")?>><?php echo "<a href='?side=invoice'>Fakturaer</a>"; ?></li>
<li <?=echo_Active_Tab("expences")?>><?php echo "<a href='?side=expences'>Utgifter</a>"; ?></li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
<button type="submit" class="btn btn-default">Søk</button>
</div>
</form>
</div>
</div>
Does anyone spot the error in my code?
EDIT: Don't mind the wrong function name, fixed and edited. The code doesn't do as I'd hoped.

Why is PJAX stopping Nestable working?

I have 3 columns in my app. Each column has an unordered list. I am using Nestable to drag and drop list items between lists. The mark up is as follows:
<div class="row-fluid span12">
<div class="cf nestable-lists">
<div id="pjax-content">
<div class="span4">
<div class="dd" id="nestable1">
<ul class="dd-list">
<li class="dd-item dd3-item" data-id="123">
<div class="dd-handle dd3-handle">Drag</div>
<div class="dd3-content">
// list content
</div>
</li>
<li class="dd-item dd3-item" data-id="456">
<div class="dd-handle dd3-handle">Drag</div>
<div class="dd3-content">
// list content
</div>
</li>
</ul>
</div>
</div>
<div class="span4">
<div class="dd" id="nestable2">
<ul class="dd-list">
<li class="dd-item dd3-item" data-id="789">
<div class="dd-handle dd3-handle">Drag</div>
<div class="dd3-content">
// list content
</div>
</li>
<li class="dd-item dd3-item" data-id="1011">
<div class="dd-handle dd3-handle">Drag</div>
<div class="dd3-content">
// list content
</div>
</li>
</ul>
</div>
</div>
<div class="span4">
<div class="dd" id="nestable3">
<ul class="dd-list">
<li class="dd-item dd3-item" data-id="1213">
<div class="dd-handle dd3-handle">Drag</div>
<div class="dd3-content">
// list content
</div>
</li>
<li class="dd-item dd3-item" data-id="1415">
<div class="dd-handle dd3-handle">Drag</div>
<div class="dd3-content">
// list content
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
This works and I can drag and drop list items between each list. The problem is when I implement PJAX.
I have a few links that use PJAX to change the url i.e. each link will update the data or order of the data in each list based on the URL. The data updates within id="pjax-content" accordingly, so it works. This is a snippet of the server side code (using CI):
if (isset($_SERVER["HTTP_X_PJAX"])) {
echo $data['contents'];
} else {
// construct views when not PJAX
}
$data['contents'] contains the html as a string.
I have the following JS libraries too (I have tried removing some of these and the problem still exists):
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="nestable.js"></script>
<script type="text/javascript" src="nestable-settings.js"></script>
<script type="text/javascript" src="bootstrap-editable.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript" src='jquery.pjax.js'></script>
<script type="text/javascript">
$(document).pjax('[data-pjax] a, a[data-pjax]', '#pjax-content');
$(document).on('pjax:send', function() {
console.log("before send");
});
$(document).on('pjax:complete', function() {
console.log("done!");
});
</script>
The Problem
When I click on one of the links PJAX works, the data is updated, the page doesn't reload and the console shows before send and done - so all is well. However, the nestable items are no longer selectable so a I can't drag and drop them. When I do a full page refresh it works and I can drag and drop.
I have compared the markup before and after (as that was a previous issue) and everything is the same.
Any suggestions on where I am going wrong? Or how to best debug this?
call nestable after your ajax complete function
$(document).on('pjax:complete', function() {
$('#nestable1,#nestable2,#nestable3').nestable();
});

Categories