jQuery append not working using json_encode - javascript

I'm trying to append an result from a database PHP insert using echo json_encode($results).
I'm, getting all the values from the post back in the JSON but the appending is not working.
Here's the jQuery side:
$('#postsubmit').click(function(){
error = 0;
// get form data
post = $('#comments').val();
topicname = $('#topicName').val();
topicid = $('#topicID').val();
pageid = $('#pageID').val();
page = $('#page').val();
sendmail = $('#sendmail').val();
galleria_pointer = $('#galleria_pointer').val();
showstatus = $('#showstatus').val();
$(this).attr('disabled','disabled');
if ($("#comments").val() == ''){
$("#comments").css({ "border": "1px solid red"});
$('.hideAdd').show();
$(this).attr('enabled','enabled');
}
$.ajax({
type: "POST",
url: "../foorumi/AjaxPost.php",
dataType: 'text',
data: "topicid="+topicid+"&pageid="+pageid+"&topicname="+topicname+"&page="+page+"&post="+encodeURIComponent(post)+"&sendmail="+sendmail+"&galleria_pointer="+galleria_pointer+
"&showstatus="+showstatus,
beforeSend : function(){
$("#loading_image").show();
$("body").css("cursor", "wait");
},
error : function(XMLHttpRequest, textStatus, errorThrown){
error = 1;
},
success : function(data) {
$("#loading_image").hide();
$("body").css("cursor", "default");
//alert(data);
dataobject = $.parseJSON(data);
var json_post_result = dataobject.post_result;
var json_error_code = dataobject.errors;
var json_topicname = dataobject.topicname;
var json_postid = dataobject.postid;
var json_topicid = dataobject.topicid;
var json_pageid = dataobject.pageid;
var url = dataobject.url;
var json_showstatus= dataobject.showstatus;
var json_post = dataobject.post;
var json_dateNow = dataobject.sentNow;
var json_galleria_pointer = dataobject.sentNow;
var json_data_html = dataobject.data_html;
var decoded = $("<div/>").html(json_data_html).text();
//alert(decoded);
if(json_post_result == true){
url_to = url;
//window.location.replace(url_to);
$(".hideAdd").fadeOut("fast",function(){
$('#ShowNew').show();
$(".divWrapperAppend").append(decoded);
});
}
}
});
});
And here's the PHP side:
$user_ = ($_SESSION['users_id']);
$post_single = utf8_decode($_POST['post']);
$pageid = $_POST['pageid'];
$topicid_ = $_POST['topicid'];
$topicname = $_POST['topicname'];
$page = $_POST['page'];
$galleria_pointer = ($_POST['galleria_pointer']);
$sendmail = ($_POST['sendmail']);
$showstatus = ($_POST['showstatus']);
$microseconds_ = ((double) microtime()) * 1000000;
$results = array();
$errors = '';
$data = array();
$sqluserinfo = "select u.username as username, u.userlevel, (SELECT 1 FROM userphotos up WHERE up.user_= '$user_' and defaultphoto = '1') as photonum
,(SELECT count(1) FROM posts p1 WHERE u.users_id = p1.user_) as usermessagecount FROM users u WHERE u.users_id = '$user_'";
$sqlusersql = mysql_query($sqluserinfo);
$username = mysql_result($sqlusersql, 0, username);
$count_posts = mysql_result($sqlusersql, 0, usermessagecount);
$ulevel = mysql_result($sqlusersql, 0, userlevel);
$photonum = mysql_result($sqlusersql, 0, photonum);
$userSendMailSQL = "select *, (SELECT 1 from mail_topic where sendmail = '1' and user_ = '$user_' and theader_ = '$topicid_') as sendmail1 FROM mail_topic WHERE user_='$user_' and theader_ = '$topicid_' order by id";
$resultsqlquery = mysql_query($userSendMailSQL)or die(mysql_error());
$sendMailto = mysql_result($resultsqlquery, 0, sendmail1);
if ($post_single == "" || strlen(preg_replace('/\W/', '', $post_single)) < 5)
{
$errors = 1;
}
if (!empty($errors)){
$data['errors'] = $errors;
$data['post_success'] = false;
$results = array("errors"=>$errors, "post_result" => $data['post_success']);
}
else{
$data['post_success'] = true;
$new_post = htmlspecialchars($post_single, ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
$insert="insert into posts (topicID, user_, Post, editdate_, updatedmicrosec) values ('$topicid_','$user_','$new_post','editdate_','$microseconds_')";
$timetoday = date("d.m.Y H:i:s");
$dateNow = date_diff_as_text($timetoday,"now") . " sitten";
//Insert data to db
mysql_query($insert);
$postid_ = mysql_insert_id();
if ($sendmail > 0){
sendmail($topicid_,$topicname,$user_,$postid_,$page);
}
updatelastread($topicid_);
$tableStyle_ajax = 'postStyleThisDay';
$tableStyleUser_ajax = 'postStyleThisDayUser';
$tableStyleNoBorder_ajax = 'postStyleThisDayNoBorder';
$styleBorder_ajax = 'style="min-height: 100%; border-right: 2px solid #87b1c8;"';
$aid_ajax = '<a name="'.$postid_.'"></a>';
$idcolor_ajax = 'color: #e82020; font-weight: bold;';
$borderbottom_ajax = 'border-bottom: 2px solid #e82020;';
$bordertop_ajax = 'border-top: 2px solid #e82020;';
if ($photonum > 0)
{
$photodiv = ('<div style="width: 89px; border: 1px solid #dadada; padding: 3px; margin: 0px 5px 5px 0px;"><img src="../profiili/userAlbums/'.$folder.'/'.$thumbnail.'"" style="width: 85px; height: 55px; border: none; padding: 2px;"/></div>');
}
$data_html = ('
<div id="'.$tableStyle_ajax.'" style="min-height: 30px; width: 885px; padding: 5px; margin-top: 5px; '.$bordertop_ajax.'>
<div style="padding: 8px 5px 3px 5px; min-height: 20px; border-bottom: 1px solid #dadada; background-color: #f7fdff;">
<div class="forumPostUser" style="float: left; width: 145px;"><a href="../kayttajat/index.php?id='.$user_.'>'.$username.'</a></div>
<div style="float: left; padding-left: 5px; width: 640px;">Lähetetty: '.$dateNow.'</div>
<div style="float: left; padding-left: 5px; '.$idcolor_ajax.'">ID: '.$postid_.'</div>
</div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="width: 130px; min-height: 65px; padding: 5px 5px 10px 5px;">
'.$photodiv.'
<div style="font-size: 11px;">Viestejä: '.$count_posts.' kpl</div>
<div style="font-size: 11px; padding-top: 3px;">Taso: '.$showstatus.'
</div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="min-width: 5px; min-height: 65px; padding: 5px 5px 10px 5px;">
<div> </div>
</div>
<div class="column" id="'.$tableStyleNoBorder_ajax.'" style="width: 730px; min-height: 65px; padding: 5px 5px 10px 5px;">
<span style="font-size: 16px; line-height: 130%;">'.$new_post.'</span>
</div>
<div id="'.$tableStyle_ajax.'" style="min-height: 30px; width: 885px; padding: 5px 5px 5px 5px; margin-top: 5px; '.$borderbottom_ajax.'">
<div style="padding: 8px 5px 3px 0px; min-height: 20px;">
<div style="font-size: 12px; width: 155px; padding-top: 20px; float: left;" class="forumPostUser">alkuun</div>
<div style="float: left; width: 300px; padding-top: 12px; border-top: 1px solid #dadada;"> </div>
<div style="float: left; width: 425px; padding-top: 5px; border-top: 1px solid #dadada;"><div style="float: left; margin-left: 240px;">
<form method="post" action="index.php?id='.$pageid.'&show='.$topicid_ .'&page='.$page.'#quoted"><input type="hidden" name="postID" value="'.$postid_.'" />
<input type="hidden" name="lainaa" value="Lainaa" />
<input type="image" src="../png/lainaa.png" /></form>
</div>
<div style="float: left;">
<form method="post" action="index.php?id='.$pageid.'&show='.$topicid_.'&page='.$page.'&postid='.$postid_.'&tag=#'.$postid_.'"><input type="hidden" name="postID" value="'.$postid_.'" /><input type="hidden" name="muokkaa" value="submit" />
<input type="hidden" name="edited" value="edited" />
<input type="image" src="../png/muokkaa.png" /></form></div>
</div>
</div>
<div style="clear: both;"></div>
</div>
</div>
<div style="clear: both;"></div>');
$data_html = htmlspecialchars($data_html, ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
if (mysql_error() != ""){
echo ('<br><p><center><b><FONT SIZE="-1" FACE="Trebuchet MS,Arial,Helvetica">There was a MySQL Error -- '.mysql_error().'</b></center></p>');
exit;
}
$url = 'http://intra.tobiasfransman.net/foorumi/index.php?id='.$pageid.'&show='.$topicid_.'&page='.$page.'&postid='.$postid_.'&tag=#'.$postid_.'';
$results = array(
"data_html" => $data_html,
"url" => $url,
"post_result" => $data['post_success']
);
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
//header('Content-type: application/x-www-form-urlencoded, charset=UTF-8');
echo json_encode($results);
It's the $data_html that I want to append, but it wont append.
Can anyone see what I'm doing wrong?
console log ouput:
{"data_html":"\r\n <div id="postStyleThisDay" style="min-height: 30px; width: 885px; padding: 5px; margin-top: 5px; border-top: 2px solid #e82020;>\r\n <div style="padding: 8px 5px 3px 5px; min-height: 20px; border-bottom: 1px solid #dadada; background-color: #f7fdff;">\r\n <div class="forumPostUser" style="float: left; width: 145px;"><a href="..\/kayttajat\/index.php?id=0>Tobba<\/a><\/div>\r\n <div style="float: left; padding-left: 5px; width: 640px;">L&auml;hetetty:&nbsp; < 1 minuutti sitten<\/div>\r\n <div style="float: left; padding-left: 5px; color: #e82020; font-weight: bold;">ID: 0<\/div>\r\n <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="width: 130px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <div style="width: 89px; border: 1px solid #dadada; padding: 3px; margin: 0px 5px 5px 0px;"><a href="..\/kayttajat\/index.php?id=0&album=1&img=2"><img src="..\/profiili\/userAlbums\/\/"" style="width: 85px; height: 55px; border: none; padding: 2px;"\/><\/a><\/div>\r\n <div style="font-size: 11px;">Viestej&auml;: 1104 kpl<\/div>\r\n <div style="font-size: 11px; padding-top: 3px;">Taso:&nbsp;<span>LIFE.IS.A..<\/span>\r\n <\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="min-width: 5px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <div>&nbsp;<\/div>\r\n <\/div>\r\n <div class="column" id="postStyleThisDayNoBorder" style="width: 730px; min-height: 65px; padding: 5px 5px 10px 5px;">\r\n <span style="font-size: 16px; line-height: 130%;">Testing testing<\/span>\r\n <\/div>\r\n <div id="postStyleThisDay" style="min-height: 30px; width: 885px; padding: 5px 5px 5px 5px; margin-top: 5px; border-bottom: 2px solid #e82020;">\r\n <div style="padding: 8px 5px 3px 0px; min-height: 20px;">\r\n <div style="font-size: 12px; width: 155px; padding-top: 20px; float: left;" class="forumPostUser"><a href="#alkuun">alkuun<\/a><\/div>\r\n <div style="float: left; width: 300px; padding-top: 12px; border-top: 1px solid #dadada;">&nbsp;<\/div>\r\n <div style="float: left; width: 425px; padding-top: 5px; border-top: 1px solid #dadada;"><div style="float: left; margin-left: 240px;">\r\n <form method="post" action="index.php?id=1&show=41&page=9#quoted"><input type="hidden" name="postID" value="0" \/>\r\n <input type="hidden" name="lainaa" value="Lainaa" \/>\r\n <input type="image" src="..\/png\/lainaa.png" \/><\/form>\r\n <\/div>\r\n <div style="float: left;">\r\n <form method="post" action="index.php?id=1&show=41&page=9&postid=0&tag=#0"><input type="hidden" name="postID" value="0" \/><input type="hidden" name="muokkaa" value="submit" \/>\r\n <input type="hidden" name="edited" value="edited" \/>\r\n <input type="image" src="..\/png\/muokkaa.png" \/><\/form><\/div>\r\n <\/div>\r\n <\/div>\r\n <div style="clear: both;"><\/div>\r\n\r\n <\/div>\r\n <\/div>\r\n <div style="clear: both;"><\/div>","url":"http:\/\/intra.tobiasfransman.net\/foorumi\/index.php?id=1&show=41&page=9&postid=0&tag=#0","post_result":true,"errors":null}

Added $data_html = utf8_decode($data_html) to the php post and now the append works as is :)

Related

Is possible to open instagram in iframe without API

another way to open instagram in iframe tag without having API
You can always check any url(example.com) is allowed in IFrame or not for a specific Origin by following method:
function isAllowededByXFrameOption({ header, origin }) {
if (header["X-Frame-Options".toLowerCase()]) {
let options = header["X-Frame-Options".toLowerCase()].toLowerCase();
if (options === "SAMEORIGIN".toLowerCase()) {
return false;
} else if (options === "DENY".toLowerCase()) {
return false;
} else if (~options.indexOf("ALLOW-FROM".toLowerCase())) {
let allowedOrigins = options.split(" ").slice(1);
return allowedOrigins.find(
_o => url.parse(_o).host === url.parse(origin).host
);
}
}
if (header["Content-Security-Policy".toLowerCase()]) {
let _options = header["Content-Security-Policy".toLowerCase()];
let CheckOriginInSource = source_name => {
_options = _options.split(";");
_options = _options.find(_o => _o.indexOf(source_name) > -1);
_options = _options.split(" ").slice(1);
return _options.find(_o => url.parse(_o).host === url.parse(origin).host);
};
if (_options.indexOf("frame-src") > -1) {
return CheckOriginInSource("frame-src");
} else if (_options.indexOf("child-src")) {
return CheckOriginInSource("child-src");
} else if (_options.indexOf("default-src")) {
return CheckOriginInSource("default-src");
} else {
return true;
}
} else {
return true;
}
}
const got = require("got");
const metascraper = require("metascraper")([
require("metascraper-author")(),
require("metascraper-date")(),
require("metascraper-description")(),
require("metascraper-image")(),
require("metascraper-logo")(),
require("metascraper-clearbit-logo")(),
require("metascraper-publisher")(),
require("metascraper-title")(),
require("metascraper-url")()
]);
const Domain = "example.com";
(async () => {
const { body: html, url, headers } = await got(Domain);
const metadata = await metascraper({ html, url });
const isAllowed = isAllowededByXFrameOption({
header: headers,
origin: "www.app4pc.com"
})
})();
You can easily embed an Instagram post using the embed link they provide.
Source: https://www.instagram.com/developer/embedding/
Example:
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/B3w_PilgaOZ/?utm_source=ig_embed&utm_campaign=loading" data-instgrm-version="12" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:540px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-511.000000, -20.000000)" fill="#000000"><g><path d="M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631"></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;"> View this post on Instagram</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <p style=" margin:8px 0 0 0; padding:0 4px;"> Today’s #WeeklyFluff is defying gravity. Meet Narcos (#narcos_cockerspaniel): He’s a happy, expressive and active dog who loves to fly.⁣ ⁣ Photo by #narcos_cockerspaniel</p> <p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;">A post shared by Instagram (#instagram) on <time style=" font-family:Arial,sans-serif; font-size:14px; line-height:17px;" datetime="2019-10-18T15:59:06+00:00">Oct 18, 2019 at 8:59am PDT</time></p></div></blockquote> <script async src="//www.instagram.com/embed.js"></script>

Content of horizontal scroll div is cut

I am inserting into my HTML using javascript. My code is being truncated/ cut off.
Here's my code:
function feedbackDiv(feedback_id, feedback_title, feedback_content, feedback_author) {
return querySnapshot.forEach(function(doc) {
const data = doc.data();
var feedback_title = data.title;
var feedback_content = data.content;
var feedback_author = data.author;
document.getElementById("küchen_feedback_p").insertAdjacentHTML('beforeend', feedbackDiv(doc.id, feedback_title, feedback_content, feedback_author));
});
};
.küchen_co {
padding: 20px;
}
.küchen_feedback_p {
overflow-x: auto;
}
.feedback_container {
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
text-align: center;
}
.feedback_container:hover {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
<div class="küchen_co center">
<div class="küchen_feedback_p center" id="küchen_feedback_p" style="display: none;">
</div>
<div class="noDataContainer_kfeedback_p" id="noDataContainer_kfeedback_p" style="text-align:center;">
<img src="./broken_heart.png" width="80px" height="auto" />
<p class="nothing_found_k küchenH">Es wurden derzeit keine Feedbacks abgesendet.</p>
</div>
</div>
<div class="feedback_container" id="feedbackDiv" style="width:300px; height: 250px; margin-right: 20px;">
<p id="feedback_id" style="display: none;">${feedback_id}</p>
<h1 class="" style="word-wrap: break-word;">${feedback_title}</h1>
<p class="" style="word-wrap: break-word;">${feedback_content}</p>
<p class="" id="feedback_author" style="display: none;">${feedback_author}</p>
</div>
But the content of the scrolling div is cutted: https://www.dropbox.com/s/8f95tjojkbpku35/scroll.PNG?dl=0
~filip
For all with further issues. The problem might be the following lines of code:
justify-content: center;
align-items:center;
text-align:center;

filter string only filter the string without spaces

as you can see on my snippets, I could search only for the first name e.g. full name"ABDOL JABAR BAKARI" and the first name is "abdol" and only the name "abdol" is utilize in the filter function which it must all the string inside that data attribute named "data-fullname" will filtered. any ideas, clues, help, suggestions, recommendation to make it search the whole string inside the data attribute named "data-fullname" and search also from the string inside the data attribute named "data-job"?
$(document).ready(function(){
$('.search_employee').on('input', function() {
var value = this.value.toLowerCase();
$('.profile').hide().filter(function() {
var name = $(this).attr('data-fullname').toLowerCase();
return value.trim().length < 1 || name.indexOf(value) === 0;
}).show();
});
});
.profile{
width: 200px;
float: left;
display: block;
margin: 5px;
border: 1px solid #ccc;
padding: 10px 0px;
}
.profile h1{
font-size: 15px;
color: 555;
padding: 5px;
margin: 0px;
text-align: center;
text-transform: uppercase;
}
.profile p{
font-size: 13px;
color: 555;
padding: 5px;
margin: 0px;
text-align: center;
text-transform: uppercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control search_employee" placeholder="Search here...">
<div id="profile_holder">
<div class="profile" data-fullname="Abdol Jabar Bakari" data-job="system developer">
<h1>Abdol Jabar Bakari</h1>
<p>System Developer</p>
</div>
<div class="profile" data-fullname="Jason Fang" data-job="database analysis">
<h1>Jason Fang</h1>
<p>Database Analysis</p>
</div>
<div class="profile" data-fullname="Mechelle Newyurk" data-job="sales officer">
<h1>Mechelle Newyurk</h1>
<p>Sales Officer</p>
</div>
<div class="profile" data-fullname="Juliver Galleto" data-job="ui/ux">
<h1>Juliver Galleto</h1>
<p>UI/UX</p>
</div>
</div>
A simple change required. Instead of checking for name.indexOf(value) !== -0;, you should check for name.indexOf(value) !== -1;
$(document).ready(function(){
$('.search_employee').on('input', function() {
var value = this.value.toLowerCase();
$('.profile').hide().filter(function() {
var name = $(this).attr('data-fullname').toLowerCase();
return value.trim().length < 1 || name.indexOf(value) !== -1;
}).show();
});
});
.profile{
width: 200px;
float: left;
display: block;
margin: 5px;
border: 1px solid #ccc;
padding: 10px 0px;
}
.profile h1{
font-size: 15px;
color: 555;
padding: 5px;
margin: 0px;
text-align: center;
text-transform: uppercase;
}
.profile p{
font-size: 13px;
color: 555;
padding: 5px;
margin: 0px;
text-align: center;
text-transform: uppercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control search_employee" placeholder="Search here...">
<div id="profile_holder">
<div class="profile" data-fullname="Abdol Jabar Bakari" data-job="system developer">
<h1>Abdol Jabar Bakari</h1>
<p>System Developer</p>
</div>
<div class="profile" data-fullname="Jason Fang" data-job="database analysis">
<h1>Jason Fang</h1>
<p>Database Analysis</p>
</div>
<div class="profile" data-fullname="Mechelle Newyurk" data-job="sales officer">
<h1>Mechelle Newyurk</h1>
<p>Sales Officer</p>
</div>
<div class="profile" data-fullname="Juliver Galleto" data-job="ui/ux">
<h1>Juliver Galleto</h1>
<p>UI/UX</p>
</div>
</div>
The problem is the condition name.indexOf(value) === 0 which matches the search term to only the start of the string.
If the searched term is not found indexOf will retrn -1, so just check the returned value is > 1 to check whether the term is present in the string like name.indexOf(value) > -1;
$(document).ready(function() {
$('.search_employee').on('input', function() {
var value = this.value.toLowerCase().trim();
if (value) {
//do this only if a filter condition is present
$('.profile').hide().filter(function() {
var name = $(this).data('fullname').toLowerCase();
return name.indexOf(value) > -1 || $(this).data('job').toLowerCase().indexOf(value) > -1;
}).show();
} else {
$('.profile').show();
}
});
});
.profile {
width: 200px;
float: left;
display: block;
margin: 5px;
border: 1px solid #ccc;
padding: 10px 0px;
}
.profile h1 {
font-size: 15px;
color: 555;
padding: 5px;
margin: 0px;
text-align: center;
text-transform: uppercase;
}
.profile p {
font-size: 13px;
color: 555;
padding: 5px;
margin: 0px;
text-align: center;
text-transform: uppercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control search_employee" placeholder="Search here...">
<div id="profile_holder">
<div class="profile" data-fullname="Abdol Jabar Bakari" data-job="system developer">
<h1>Abdol Jabar Bakari</h1>
<p>System Developer</p>
</div>
<div class="profile" data-fullname="Jason Fang" data-job="database analysis">
<h1>Jason Fang</h1>
<p>Database Analysis</p>
</div>
<div class="profile" data-fullname="Mechelle Newyurk" data-job="sales officer">
<h1>Mechelle Newyurk</h1>
<p>Sales Officer</p>
</div>
<div class="profile" data-fullname="Juliver Galleto" data-job="ui/ux">
<h1>Juliver Galleto</h1>
<p>UI/UX</p>
</div>
</div>

Button and POST method - Not allowing execution of javascript method

I'm having a some trouble with a button, I'm using a DIV that has a POST method inside of it, however, this button in question doesn't need the POST method, so:
<div id="lightA" class="white_content" height="300">
<h1>Adivinar...</h1>
<h2>Que personaje escoges?:</h2>
<form type="post">
<input type="text" list="personajes">
<datalist id="personajes" style="display:block">
<?php
session_start();
include "config.php";
if(isset($_SESSION["user_name"]))
{
$select = "SELECT nombre_personaje FROM partida WHERE user_name =".$_SESSION["user_name"]."AND personaje_activo = 'T'";
$query = mysqli_query($con, $select);
$rows = mysqli_num_rows($query);
$cont = 0;
$tableval;
if($rows > 0)
{
while($row = mysqli_fetch_array($query))
{
if($row['personaje_activo'] = "T")
{
=$tableval."<option value=\"".$row['']."\">";
}
}
}
else
{
?>
<?
}
}
echo $tableval;
?>
</datalist>
<button type="submit" action="submit_character.php" name="select" style="display:inline">Elegir!</button>
</form>
<button onclick:"javascript:cerrarPop('lightA')">Cancelar</button>
</div>
Now this is the funny part, <button onclick:"javascript:cerrarPop('lightA')">Cancelar</button> isn't executing anything at all, I was thinking, well just put the button inside the post, however the page refresh itself and executes <body background="imagen.jpg" onload="javascript:mostrarPop('lightP')"> which I don't need, then I was looking how to set a cookie for that pop DIV, but I have a limited knowledge in AJAX.
Here's also my JS script:
<script type="text/javascript">
function mostrarPop(name) {
document.getElementById(name).style.display='block';
document.getElementById('fade').style.display='block';
}
function cerrarPop(name) {
document.getElementById(name).style.display='none';
document.getElementById('fade').style.display='none';
}
</script>
Any help is appreciated, AJAX would be awesome, I'm reading some code right however is a bit confusing.
Thanks in advance.
Update
Here's the entire code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Guess who? - Lobby</title>
<style type="text/css">
.black_overlay{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.6;
opacity:.80;
filter: alpha(opacity=80);
}
.white_content {
text-align: center;
display: none;
margin-top: 50px;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
width: 35%;
height: 500px;
padding: 16px;
border: 16px solid orange;
background: rgba(0,0,0,.8);
z-index:1002;
overflow: auto;
}
input[type="text"]{
width:173px;
display:inline;
margin-left:5px;
}
body { width:960px; margin:0 auto;}
div.chatbox{
position:fixed;
display:table;
border-collapse: collapse;
width: 250px;
height: 350px;
border-radius: 9px;
padding: 0.5em;
background: rgba(0,0,0,.5);
margin-top:25px;
margin-bottom:100px;
margin-right:50px;
margin-left:705px;
}
div.gamebox{
position:fixed;
background: rgba(0,0,0,.5);
width: 630px;
height: 560px;
border-radius: 9px;
padding: 0.5em;
margin-top:25px;
margin-bottom:100px;
margin-right:50px;
margin-left:25px;
}
div.optionbox{
position:fixed;
border-collapse: collapse;
width: 235px;
height: 190px;
border-radius: 9px;
padding: 0.5em;
background: rgba(0,0,0,.5);
margin-top:395px;
margin-bottom:100px;
margin-right:50px;
margin-left:705px;
}
h1 {
margin-top: 10px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: center;
font-size: 30px;
color: #F00;
text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;
}
h2 {
display: inline;
margin-top: 10px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: left;
font-size: 25px;
color: #FFF;
}
iframe {
background-color: #FFF;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
}
input[type="submit"]{
background-color: #FFF;
margin-top: 1px;
margin-left: 5px;
margin-right: 5px;
}
</style>
<script type="text/javascript">
mostrarPop = function(name) {
document.getElementById(name).style.display='block';
document.getElementById('fade').style.display='block';
}
cerrarPop = function(name) {
document.getElementById(name).style.display='none';
document.getElementById('fade').style.display='none';
}
</script>
</head>
<body background="imagen.jpg" onload="mostrarPop('lightP')">
<div id="lightP" class="white_content">
<h1>Tu personaje secreto es:</h1>
<?php
session_start();
include "config.php";
if(isset($_SESSION["user_name"]))
{
$selectcategoria = "SELECT DISTINCT id_partida, id_categoria FROM partida WHERE user_name =".$_SESSION["user_name"];
$querycategoria = mysqli_query($con, $selectcategoria);
$rowcategoria = mysqli_fetch_array($querycategoria);
$personajenum = rand(0,23);
$selectpersonaje = "SELECT nombre_personaje, foto_personaje FROM Categoria WHERE id_personaje =".$personajenum;
$querypersonaje = mysqli_query($selectpersonaje);
$rowpersonaje = mysqli_fetch_array($querypersonaje);
$selectturno = "SELECT user_name_retador, user_name_oponente FROM WHERE user_name =".$_SESSION["user_name"];
$queryturno = mysqli_query($con, $selectcategoria);
$rowturno = mysqli_fetch_array($query);
if($_SESSION["user_name"]=$rowturno["user_name_oponente"]){
$insertestado = "INSERT INTO estadojugador(id_partida, user_name, turno_activo, personaje_secreto) VALUES(".$row['id_partida'].", ".$_SESSION["user_name"].", "."false".", ".$rowpersonaje["nombre_personaje"].")";
$queryestado = mysqli_query($insertestado);
}
else
{
$insertestado = "INSERT INTO estadojugador(id_partida, user_name, turno_activo, personaje_secreto) VALUES(".$row['id_partida'].", ".$_SESSION["user_name"].", "."true".", ".$rowpersonaje["nombre_personaje"].")";
$queryestado = mysqli_query($insertestado);
}
echo "<img src=\"categorias/".$rowpersonaje["foto_personaje"]."\" width=\"240\" height=\"360\" style=\"display:block; margin: 0 auto;></img>";
}
?>
<button onclick="cerrarPop('lightP')" style="margin-top:10px; margin: 0 auto;">Continuar!</button>
</div>
<div id="lightA" class="white_content" height="300">
<h1>Adivinar...</h1>
<h2>Que personaje escoges?:</h2>
<form type="post">
<input type="text" list="personajes">
<datalist id="personajes" style="display:block">
<?php
session_start();
include "config.php";
if(isset($_SESSION["user_name"]))
{
$select = "SELECT nombre_personaje FROM partida WHERE user_name =".$_SESSION["user_name"]."AND personaje_activo = 'T'";
$query = mysqli_query($con, $select);
$rows = mysqli_num_rows($query);
$cont = 0;
$tableval;
if($rows > 0)
{
while($row = mysqli_fetch_array($query))
{
if($row['personaje_activo'] = "T")
{
=$tableval."<option value=\"".$row['']."\">";
}
}
}
else
{
?>
<?
}
}
echo $tableval;
?>
</datalist>
<button type="submit" action="submit_character.php" name="select" style="display:inline">Elegir!</button>
</form>
<button onclick:"cerrarPop('lightA')">Cancelar</button>
</div>
<div id="fade" class="black_overlay"></div>
<div class="chatbox">
<table width="240" height="250">
<form method="post" action="handler_partidas.php">
<tr>
<td><iframe src="messages_partidas.php" name="iframe" width="230" height="305"></iframe></td>
</tr>
<tr>
<td><input type="text" name="message"> <button type="submit" name="send">Enviar</button>
</tr>
</form>
</table>
</div>
<div class="gamebox">
<table width="240" height="250">
<form method="post" action="fill_table.php">
</form>
</table>
</div>
<div class="optionbox">
<h1>Opciones</h1>
<button onclick="">Rendirse</button>
<button onclick="javascript:mostrarPop('lightA')">Adivinar...</button></br>
<button type="submit" name="yes">Si</button>
<button type="submit" name="no">No</button>
</div>
</body>
</html>
There is 2 problem on your code first one is button onclick event. It should be like;
<button onclick="cerrarPop('lightA')">Cancelar</button>
Second problem is function defination. It is also be like;
cerrarPop = function (name) {
document.getElementById(name).style.display='none';
document.getElementById('fade').style.display='none';
}
jsfiddle link

whenever Click on submit of PopupForm from another view then it is showing default view(month) in fullcalendar

In my Application Everything Work Fine add/edit but my main Problem is IF i am on a 'agendaWeek' of Fullcalendar and try to submit or cancel the form then it is going to Month View
Updated Code:
JAVASCRIPT:
<script>
var globalEvent = null;
$(document).ready(function() {
var count=0;
var liveDate=new Date();
var dat = new Date();
var d = dat.getDate();
var m = dat.getMonth();
var y = dat.getFullYear();
var calendar = $('#calendar').fullCalendar({
selectable: true,
selectHelper: true,
select: function(startDate, endDate, allDay, jsEvent, view) {
var startDate1=$.fullCalendar.formatDate(startDate, "yyyy-MM-dd HH:mm:ss");
var endDate1=$.fullCalendar.formatDate(endDate, "yyyy-MM-dd HH:mm:ss");
document.getElementById('mode').innerHTML = "ADD :"+"<img src='<?php echo base_url();?>/assets/images/close.png' style='float:right; height:35px; width:35px; margin-top:-7px;' id='closeimg' name='closeimg'>";
document.getElementById('starting').innerHTML = startDate1;
document.getElementById('ending').innerHTML = endDate1;
$("#ginger").show();
$("#closeimg").click(function(){
$("#ginger").hide();
});
$("#eventName").focus();
$("#submit").click(function(){
var title=$("#eventName").val();
calendar.fullCalendar('renderEvent',{
title: title,
start: startDate1,
end: endDate1,
allDay: false},
true // make the event "stick"
);
var dataString={};
dataString['eventName']=title;
dataString['startTime']=startDate1;
dataString['endTime']=endDate1;
$.ajax({
type : 'POST',
dataType : 'json',
url : '<?php echo base_url(); ?>data/insert',
data: dataString,
success: function(data) {
alert("data insert SuccessFully1");// I get this alert
var currentView = calendar.fullCalendar('getView');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('changeView', currentView.name)
calendar.fullCalendar('unselect');
calendar.fullCalendar('refetchEvents');
$("#ginger").hide();
if(data.success){
alert("Data insert suceessfully 2");// i can't get this alert
}
}
});
});
},
});
});
</script>
CSS:
body {
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 70%;
margin: 0 auto;
}
#popup{
padding-left: 0%; padding-top:17%; display: block; top: 0; left: 37%; z-index:1007; opacity: 1; transform: scale(1);
height: auto;
overflow: auto;
position: absolute;
width:auto;
}
#data{
background-color: #ffffff;
color:#585858;
width:400px;
display:block;
z-index: 100;
padding:0px;
font-family: arial;
font-weight: bold;
border-radius: 7px 7px 0px 0px;
border:1px solid #C5C5C5;
}
#popup textarea{
width:200px;
height:60px;
border-radius: 5px;
vertical-align: top;
}
#detail{
/* display: none;*/
position:fixed;
top:0;
left:0;
z-index:1;
width:100%;
height:100%;
background-color:#000;
filter:alpha(opacity=50);
opacity:.5;
}
.mode{
width:99%;
background-color: #8DB3CC;
background-image:url("<?php echo base_url();?>assets/kendou/styles/textures/highlight.png");
background-position: 0 center;
background-repeat: repeat-x;
height:30px;
padding: 5px 0px 0px 5px;
font-size: 15px;
font-weight:normal;
border-bottom:1px solid #C5C5C5;
border-radius: 7px 7px 0px 0px;
}
.dropdown{
border-style: solid;
border-width: 1px;
padding: 2px 22px 2px 2px;
display: block;
cursor: default;
position: relative;
text-align: right;
line-height:1px;
border-radius: 2px 2px 2px 2px;
color: #2E2E2E;
border-color: #C5C5C5;
}
HTML :
<div class="wrapper">
<div id='calendar'></div>
<div style="display:none;" id="ginger">
<div id="detail"> </div>
<form name="addData" id="addData" action="" method="post">
<div id="popup">
<div id="data">
<div id="mode" value="" class="mode">
<!--<img src="<?php echo base_url();?>/assets/images/close.png" style="float:right;"/>-->
<img src="<?php echo base_url();?>/assets/images/logo.png">
</div><br>
<div style="padding:10px;">
<label for="timing">Timing: <span id="starting"></span> to <span id="ending"></span></label><br><br>
<label for="eventName">Description : </label>
<textarea name="eventName" id="eventName"type="text" value=""></textarea><br><br>
<label for="AgentName"><b>Agent Name*</b></label>
<input name="AgentName" id="AgentName"/>
<label for="UserName">UserName : </label>
<select name="UserName" id="UserName" value=""></select><br><br>
<input type="button"class="k-button" name="submit" id="submit" value="submit">//Changes here
<input type="reset" name="reset" class="k-button" id="reset" value="Reset">//changes here
<input type="button"class="k-button" name="cancel" id="cancel" value="Cancel">//changes here
</div>
</div>
</div>
</form>
</div>
</div>
You can combine getView and changeView:
//remember current view
var currentView = calendar.fullCalendar('getView');
calendar.fullCalendar('refetchEvents');
//set view type
calendar.fullCalendar('changeView', currentView.name)

Categories