Isotope .ajax() not work - php

I appreciate any help you can give me .
I commented I'm doing an infinite scroll through a foreach php and ajax to load the part of the page that I need, the only detail is that isotope use and when I try to load the new content in the isotope in the sucess function ajax , not load anything, the code above the call if the content loads correctly but not within the isotope.
This is the content of foreach
<ul class="projects_wrapper">
<?php if(isset($feed['gallery']['data'])) { ?>
<?php foreach($feed['gallery']['data'] as $k=>$v){ ?>
<li class="mix <?php echo strtolower($v['parent']['title']); ?>">
<div class="project_item">
<img class="project_item_img" src="<?php echo $v['logo']['src-s'];?>" alt="">
<div class="project_item_description">
<h3 class="project_item_title"><?php echo $v['title']; ?></h3>
<p><?php echo $v['description'];?></p>
<a class="button button_view button_project" href="/<?php echo $v['permalink'];?>">View More</a>
</div>
</div>
</li>
<?php } ?>
<?php } ?>
<div id="loadmoreajaxloader" style="display:none;"><center><img src="http://www.iec.ch/img/loading_sliders_2.gif" /></center></div>
</ul>
This is the content for javascript
var $isotope_container = $('.projects_wrapper');
var current = 2;
var catg = 'all';
$(document).ready(function(){
setTimeout(function(){
$isotope_container.isotope({
itemSelector: '.mix'
});
},1000);
// bind filter button click
$('.filter-link').on( 'click', function() {
catg = $(this).data('filter');
$( ".mix" ).filter(catg).css( "background-color", "red" );
$('.filter-link').removeClass('selected');
$(this).addClass('selected');
var filterValue = $( this ).attr('data-filter');
//use filterFn if matches value
//filterValue = filterFns[ filterValue ] || filterValue;
$isotope_container.isotope({ filter: filterValue });
});
/*$('.add_more').on('click',function(){
var elems = getItemElement().add( getItemElement() ).add( getItemElement() );
//console.log(elems);
// append elements to container
$isotope_container.append(elems).isotope('appended',elems);
});*/
$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height())
{
$('div#loadmoreajaxloader').show();
$.ajax({
url: "/projects",
data: {pag: current, content_only: 1, category: catg},
success: function(data)
{
if(data)
{
//$(".projects_wrapper").append(data);
$(".projects_wrapper").isotope("appended",data);
$('div#loadmoreajaxloader').hide();
current++;
console.log('Me Ejecuto');
}else
{
$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
console.log('Termine');
}
}
});
}
});
});

i resolve this for destroy isotope and reconstruct after like this:
function redo_isotope(){
$isotope_container.isotope('destroy');
$isotope_container.isotope({
itemSelector: '.mix'
},1000);
}
var $isotope_container = $('.projects_wrapper');
var current = 2;
var catg = 'all';
$(document).ready(function(){
setTimeout(function(){
$isotope_container.isotope({
itemSelector: '.mix'
});
},1000);
// bind filter button click
$('.filter-link').on( 'click', function() {
catg = $(this).data('filter');
$( ".mix" ).filter(catg).css( "background-color", "red" );
$('.filter-link').removeClass('selected');
$(this).addClass('selected');
var filterValue = $( this ).attr('data-filter');
//use filterFn if matches value
//filterValue = filterFns[ filterValue ] || filterValue;
$isotope_container.isotope({ filter: filterValue });
});
/*$('.add_more').on('click',function(){
var elems = getItemElement().add( getItemElement() ).add( getItemElement() );
//console.log(elems);
// append elements to container
$isotope_container.append(elems).isotope('appended',elems);
});*/
$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height())
{
$('div#loadmoreajaxloader').show();
$.ajax({
url: "/projects",
method: "get",
data: {pag: current, content_only: 1, category: catg},
success: function(data)
{
if(data)
{
$(".projects_wrapper").append(data);
redo_isotope();
//$(".projects_wrapper").append(data);
$('div#loadmoreajaxloader').hide();
current++;
}else
{
$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
}
}
});
}
});
});

Related

How to post and update jQuery Serialize using AJAX

Please note, I have gone through the below StackOverflow question which is exactly what i need but unfortunately, it isn't posting
Question similar to
My Code -
Test.php
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
} );
</script>
<ul id="sortable">
<li id="item-1">Item 1</li>
<li id="item-2">Item 2</li>
</ul>
Span 1: <span id="span"></span>
Span2: <span id="span2"></span>
<script>
$(document).ready(function () {
$('ul').sortable({
axis: 'y',
stop: function (event, ui) {
var data = $(this).sortable('serialize');
$('#span2').text(data);
$.ajax({
data: data,
type: 'POST',
url: 'test2.php',
success: function(data){
$("#span").text(data);
}
});
}
});
});
</script>
Test2.php
<?php
include('../db.php');
$date = $_POST["data"];
$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE table SET something = '$something'
WHERE id = '$id'";
if(mysqli_query($conn, $sql)){
echo $date;
}
$conn->close();
?>
Can anyone help me out why the data is not posting to test2.php page
and
how can i sort the table using the data posted to test2.php
Thanks in advance.
For those who came across the same problem here's the solution :
Test.php
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
} );
</script>
<ul id="sortable">
<?php
$q = ' SELECT * FROM temp';
$result = mysqli_query($conn, $q);
if ($result->num_rows > 0) {
while( $items = $result->fetch_assoc() ){
?>
<li id='sort_<?php echo $items['id'] ?>'>
<ul style="display:inline-block;"><?php echo $items['name'] ?></ul>
<ul style="display:inline-block;"><?php echo $items['name'] ?></ul>
</li>
<?php
}
}
?>
</ul>
<script>
$(document).ready(function () {
$('#sortable').sortable({
opacity: 0.325,
tolerance: 'pointer',
cursor: 'move',
update: function(event, ui) {
var post = $(this).sortable('serialize');
$.ajax({
type: 'POST',
url: 'test2.php',
data: post,
dataType: 'json',
cache: false,
success: function(output) {
console.log('success -> ' + output);
},
error: function(output) {
console.log('fail -> ' + output);
}
});
}
});
});
$('#sortable').disableSelection();
</script>
Test2.php
<?php
$isNum = false;
foreach( $_POST['sort'] as $key => $value ) {
if ( ctype_digit($value) ) {
$isNum = true;
} else {
$isNum = false;
}
}
if( isset($_POST) && $isNum == true ){
$orderArr = $_POST['sort'];
$order = 0;
if ($stmt = $conn->prepare(" UPDATE temp SET o_id = ? WHERE id=? ")) {
foreach ( $orderArr as $item) {
$stmt->bind_param("ii", $order, $item);
$stmt->execute();
$order++;
}
$stmt->close();
}
echo json_encode( $orderArr );
$conn->close();
}
?>
Hope it helps the one in need.

2 stage button in jQuery

I am new to jQuery so please don't judge me too harshly!
I'm making a page which lists videos, under each video there is a voting button. The button works in 2 stages, first you click it which expands the button, then the second click should confirm the vote using PHP/Ajax. If you click another button before submitting it should reset the first.
I put together the below to try and accomplish this, the first section is to expand the button, then the second is to submit the vote. It kind of works, but I noticed that if you click on one button, then another, then back to the first it submits the vote. Any ideas of how I can get this working? Or a better way of working?
Thanks in advance!
<script>
$(window).load(function(){
$("ul li .button").click(function() {
$("ul li .button").removeClass("active-button");
$("ul li .button").text("Vote for this");
$(this).addClass("active-button");
$(this).text("Submit vote");
stop;
});
});
$(document).on("click", "ul li .button", function () {
if ( $(this).hasClass( "active-button" ) ) {
$("ul li .active-button").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if (name=='up')
{
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
});
}
});
</script>
<ul class="videos clearfix">
<?php include('config.php');
$sql=mysql_query("SELECT * FROM messages LIMIT 4");
while($row=mysql_fetch_array($sql))
{
$msg=$row['msg'];
$mes_id=$row['mes_id'];
$up=$row['up'];
$title=$row['title'];
?>
<li>
<h2><?php echo $title; ?></h2>
<?php echo $msg; ?>
<div id="<?php echo $mes_id; ?>" name="up" class="button vote">Vote for this</div>
</li>
?php } ?>
</ul>
Dont have two seperate click handlers, combine them into one:
$(document).on("click", "ul li .button", function () {
if ( $(this).hasClass( "active-button" ) ) {
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if (name=='up')
{
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
}else{
$("ul li .button").removeClass("active-button");
$("ul li .button").text("Vote for this");
$(this).addClass("active-button");
$(this).text("Submit vote");
}
});

Location of CSS file in a php template

I'm doing some editing work for a friends business and the wordpress template was written in a very archaic way. I've figured out how most of the code works, but the one thing that is eluding me is where the file is referencing the css information it isn't importing it in any of the usual ways and it isn't using the main wordpress themes css file. I can't locate the resource in firebug either. Can anyone help me understand how this code works? I'm specifically trying to access the singleStyle div's css info
url:
http://wp.rafelshearling.com/?page_id=319
code:
<?php
/**
* The template used for displaying page content in page.php
*
* #package WordPress
* #subpackage Twenty_Eleven
* #since Twenty Eleven 1.0
<?php the_ID(); ?>
post_class();
*/
?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php if(is_page( array( 319, 321 ) ) ) { ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<?php if(is_page( 319 ) ) { // Mens ?>
<script>
var pageNum = 1;
var catIndex = 0;
var pageMax, catSlugList = ["jackets"];
var originalCat = catSlugList[catIndex];
var originalCatID = 9;
$(function() {
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
$(".childrenUls a").click( function(e){
return false;
});
$("#collectionNav p a").click( function(e){
if(this.getAttribute("href") === "#Back"){
if(pageNum === 1){
return false;
} else {
pageNum--;
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
}
} else if(this.getAttribute("href") === "#More"){
if(pageNum < pageMax){
pageNum++;
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
} else {
return false
}
}
return false;
});
});
</script>
<ul class="childrenUls cMe">
<?php wp_list_categories('child_of=5&orderby=id&order=DESC&title_li='); ?>
</ul>
<?php } else if(is_page( 321 ) ) { // Womens ?>
<script>
var pageNum = 1;
var catIndex = 0;
var pageMax, catSlugList = ["jackets-vests-assessories","hip-34-length","full-length"];
var originalCat = catSlugList[catIndex];
var originalCatID = 8;
$(function() {
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
$(".childrenUls a").click( function(e){
catIndex = $(".childrenUls a").index(this);
pageNum = 1;
$.ajax({
url: '/?json=get_category_posts&slug='+catSlugList[catIndex]+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
return false;
});
$("#collectionNav p a").click( function(e){
if(this.getAttribute("href") === "#Back"){
if(pageNum===1){
if(catIndex === 0){
return
} else {
pageNum = 1;
catIndex--;
originalCat = catSlugList[catIndex];
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
}
} else {
pageNum--;
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
}
} else if(this.getAttribute("href") === "#More"){
if(pageNum===pageMax){
if(catSlugList.length-1 === catIndex){
return
} else {
pageNum = 1;
catIndex++;
originalCat = catSlugList[catIndex];
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
}
} else if(pageNum < pageMax){
pageNum++;
$.ajax({
url: '/?json=get_category_posts&slug='+originalCat+'&count=12&page='+pageNum+'&exclude=categories,type,url,title_plain,status,excerpt,comments,comment_count,comment_status,tags,attachments,modified,date,author',
success: function(data) {
$("#stylesDiv, #viewLargerDiv").empty();
pageMax = data.pages;
var $collectionDiv = $("#styleCollectionDiv").children("div:eq(1)");
var $showLargerDiv = $("#viewLargerDiv");
for(var i in data.posts){
$collectionDiv.append("<div class='singleStyle'>"+data.posts[i].content+"<p>"+data.posts[i].title+"</p></div>");
}
$showLargerDiv.append($collectionDiv.children("div:eq(0)").clone());
$("#stylesDiv .singleStyle").mouseenter( function(e){
$("#viewLargerDiv").empty().append($(this).clone());
});
$(".childrenUls a").removeClass("active");
$(".childrenUls a:eq("+catIndex+")").addClass("active");
}
});
} else {
return false
}
}
return false;
});
});
</script>
<ul class="childrenUls">
<?php wp_list_categories('child_of=4&orderby=id&order=DESC&title_li='); ?>
</ul>
<?php } ?>
<br style="clear:both;" />
<div id="largeViewDiv">
<div><p>Place mouse over thumbnails to view larger.</p></div>
<div id="viewLargerDiv"></div>
</div>
<div id="styleCollectionDiv">
<div id="collectionNav"><p class="cMe"><a class="backButton" href="#Back">< Back</a><a class="moreButton" href="#More">More ></a></p></div>
<div id="stylesDiv"></div>
</div>
<br style="clear:both;" />
<?php } else { ?>
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
<?php } ?>
</div><!-- .entry-content -->
<?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<br><br><br><span class="edit-link">', '</span>' ); ?>
CSS for most Wordpress templates is in the wp-content>themes>theme_name folder, it's almost always called style.css
If I remember right the CSS is referenced in the header.php in the themes main folder too.

Why is this facebook app refreshing endlessly

I kindly request that you help me identify the reason in the code why my app keeps refreshing endlessly. This does not allow me to navigate to other pages, Iam a learner in php and I suspect this could be the issue, help. Could it be a problem with the php arrangement?
Here is the code in index.php
<script type="text/javascript">
$(document).ready(function() {
$('#premium_b').click(function(e) {
e.preventDefault();
$('#tabs').tabs( "select" , 4 );
});
$('#tabs').bind('tabsselect', function(event, ui) {
if (ui.index == 4 )
$('#premium_b').css ('display', 'none');
else
$('#premium_b').css ('display', 'block');
});
});
</script>
<div id="bloc_134" class="li_bloc"><ul class="menu"><li>Home
</li>
<li>Config
</li>
<li>Customize
</li>
<li>Export
</li>
<li>Premium
</li>
<li>Statistics
</li>
<li>Doc
</li>
<li>About
</li>
<li>Other Apps
</li>
<li>FAQ
</li>
</ul>
Upgrade to Premium to get white branding and help us improve your favourite apps! : Click her
<div class="clear"></div>
</div>
</div>
<div id="alerts">
</div>
<div id="zone2" class="li_zone li_x1 li_y2">
<div id="contact_form_about"><div class="zone2">
</div></div>
<div id="contact_form_config"><div class="zone2"><script type="text/javascript">
function refreshApp (url) {
$.get(url, function(data) {
$('*').html(data);
});
}
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#tab_info_form_0').ajaxForm(options);
});
function addToPage() {
var obj = {
method: 'pagetab',
redirect_uri: 'https://apps.facebook.com/mtkenya-dev/?page_id=#contact_form_config',
};
FB.ui(obj);
}
</script>
<script>top.location.href='https://www.facebook.com/dialog/oauth?client_id=461688580525581&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmtkenya-dev%2F%3Ftab%3Dcontact_form_config&scope=email,manage_pages'</script></div>
<div class="zone2"><script type="text/javascript">
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#contact_form').ajaxForm(options);
$('#customize_css').ajaxForm(options);
});
</script>
<div id="bloc_133" class="li_bloc"><p>Page non trouv?e</p>
</div>
</div>
</div>
<div id="contact_form_css"><div class="zone2"><script type="text/javascript">
function refreshApp (url) {
$.get(url, function(data) {
$('*').html(data);
});
}
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#tab_info_form_0').ajaxForm(options);
});
function addToPage() {
var obj = {
method: 'pagetab',
redirect_uri: 'https://apps.facebook.com/mtkenya-dev/?page_id=#contact_form_css',
};
FB.ui(obj);
}
</script>
<script>top.location.href='https://www.facebook.com/dialog/oauth?client_id=461688580525581&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmtkenya-dev%2F%3Ftab%3Dcontact_form_css&scope=email,manage_pages'</script></div>
</div>
<div id="contact_form_doc"><div class="zone2"><script type="text/javascript">
$(function() {
$("#bloc_223").tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html( "Couldn't load this tab. We'll try to fix this as soon as possible. ");
}
},
cache: true
});
});
</script>
</div>
</div>
<div id="contact_form_export"><div class="zone2"><script type="text/javascript">
function refreshApp (url) {
$.get(url, function(data) {
$('*').html(data);
});
}
$(document).ready(function() {
var options = {
success: showResponse,
beforeSubmit: disableButton
};
$('#tab_info_form_0').ajaxForm(options);
});
function addToPage() {
var obj = {
method: 'pagetab',
redirect_uri: 'https://apps.facebook.com/mtkenya-dev/?page_id=#contact_form_export',
};
FB.ui(obj);
}
</script>
<script>top.location.href='https://www.facebook.com/dialog/oauth?client_id=461688580525581&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fmtkenya-dev%2F%3Ftab%3Dcontact_form_export&scope=email,manage_pages'</script></div>
<div id="footer" class="li_zone li_x1 li_y4"> </div>
</div>
</body>
</html>
Well, I see 3 times:
top.location.href=....
without any condition and not in a function call. That would certainly keep your page jumping.

Deleting a list item <li> with jquery?

I'm trying to delete a li item using jquery, but its not working. Here's my code:
the html file:
<li>
<img class="avatar" src="images/$picture" width="48" height="48" alt="avatar" />
<div class="tweetTxt">
<strong>$username</strong> $auto
<div class="date">$rel</div>
$reply_info
<div class="date"></div>
<a class ="delbutton" href="#" id = $id> Delete </a>
</div>
<div class="clear"></div>
</li>
The jquery file:
$(function () {
$(".delbutton").click(function () {
var del_id = element.attr("id");
var info = 'id=' + del_id;
if (confirm("Sure you want to delete this update? There is NO undo!")) {
$.ajax({
type: "POST",
url: "delete.php",
data: info,
success: function () {}
});
$(this).parents(".record").animate({
backgroundColor: "#fbc7c7"
}, "fast")
.animate({
opacity: "hide"
}, "slow");
}
return false;
});
});
the delete.php file:
<?php
include("includes/connect.php");
if($_POST['id'])
{
$id=$_POST['id'];
$sql = "delete from {$prefix}notes where id='$id'";
mysql_query( $sql);
}
?>
There is no element in your HTML with a class of record. I would try something like this:
<li class="record">
<!-- a bunch of other stuff -->
<a class="delbutton" href="#">Delete</a>
</li>
then in the JS:
$(function ()
{
$(".delbutton").click(function ()
{
if (confirm("..."))
{
$.ajax({ /* ... */});
$(this).closest(".record").fadeOut();
}
return false;
});
});
If your div look like this:
<ul>
<li>One | <a href='#' class='delete'>Delete</a></li>
<li>Two | <a href='#' class='delete'>Delete</a></li>
<li>Three | <a href='#' class='delete'>Delete</a></li>
<li>Four | <a href='#' class='delete'>Delete</a></li>
</ul>
jQuery:
jQuery(document).ready(function(){
jQuery('.delete').live('click', function(event) {
$(this).parent().fadeOut()
});
});​
Check: http://jsfiddle.net/9ekyP/
EDIT:
You can remove your li after getting response in success function something like this:
jQuery(document).ready(function(){
jQuery('.delbutton').live('click', function(event) {
$.ajax({
type: "POST",
url: "delete.php",
data: info,
success: function(){
$(this).parent().parent().fadeOut();
}
});
});
});​
There are several issues with your code...
element.attr("id") references undeclared element but this should probably be $(this).attr("id")
The <li> block has no class ".record" either
EDIT: You only fade your <li> but do not actually remove it from the DOM (don't know if this was deliberate though)
The <a>'s ID is not quoted (and not escaped either... as are the other strings you insert in PHP (EDIT) and the ID you use in your delete script - this is very dangerous as it allows cross-site scripting / XSS and SQL injection as TokIk already pointed out)
PHP:
echo '<li class="record">
<img class="avatar" src="images/'.htmlentities($picture).'" width="48" height="48" alt="avatar" />
<div class="tweetTxt">
<strong>'.htmlentities($username).'</strong> '.htmlentities($auto).'
<div class="date">'.htmlentities($rel).'</div>'.htmlentities($reply_info).'<div class="date"></div> <a class="delbutton" href="#" id="'.htmlentities($id).'"> Delete </a>
</div>
<div class="clear"></div>
</li>';
JavaScript:
$(document).ready(function() {
$(".delbutton").click(function(){
var del_id = $(this).attr("id");
var info = 'id=' + del_id;
if(confirm("Sure you want to delete this update? There is NO undo!")) {
$.ajax({
type: "POST",
url: "delete.php",
data: info,
success: function(){
alert('success');
},
error: function(){
alert('error');
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
EDIT: Delete script (note the additional error check that $_POST['id'] exists and the pseudo-function for quoting the ID):
<?php
include("includes/connect.php");
if( isset($_POST['id']) ) {
$id = quote($_POST['id']);
$sql = "delete from {$prefix}notes where id='$id'";
mysql_query( $sql);
}
?>
I am assuming that '.records' is the container.
You can pass through your ID value to make <li> unique, result being:
<li id='record_12'>
//CONTENT
</li>
<li id='record_13'>
//CONTENT
</li>
And change your SUCCESS script to the following:
$(".delbutton").click(function(){
var del_id = element.attr("id");
var info = 'id=' + del_id;
if(confirm("Sure you want to delete this update? There is NO undo!"))
{
$.ajax({
type: "POST",
url: "delete.php",
data: info,
success: function(){
//Getting the unique LI and fading it out
$('#record_' + del_id).fadeOut();
}
});
Your code works fine well.I was trying to code a form that has multiple textbox, then after each textbox threre will be link called add which POST call the other php called addnew.php.
In addnew.php data will we added to database(postgres). But I am geting problem while getting the post variable itself.
this is my code for form (I will chage for multiple textbox once it works fine)
script:
<script type='text/javascript'>
$(window).load(function() {
jQuery(document).ready(function() {
jQuery('.add').live('click', function(event) {
var da = $('form#myform').serialize();
alert(da);
$.ajax({
type: "POST",
url: "addnew.php",
data:da,
success: function(data) {
if (data === "ok") {
$(this).parent().fadeOut();
$('#results').html(data);
}
else {
alert(data);
}
}
});
});
});
});
Form
<form name='myform' id='myform'>
<input name='da' type='text' id='da' value='none'>
<a href='#' class='add'>Add</a>
</form>
addnew.php code here
<? php
if( isset($_POST['da']) )
{
echo (da);
}
?>

Categories