PDA

View Full Version : Trying to insert page in a div with .load on jquery



Bicklo
11-23-2016, 08:58 PM
I am trying to insert a page in a div after a button click, the buttons get there text from a database.

This is the php part



<?php


$test = mysql_query("SELECT item FROM items");


while ($row = mysql_fetch_array($test)){
echo '<a href="" align-left = 10px;><div class="item">'.$row['item'].'</div></a>';


}


?>



Jquery



<script type="text/javascript">


$(".keuze").on('click', '.item', function(){


var $deel = $(this).text();

if ( $deel == "Statuten"){


$('#uitkomst').load('statuten.php');

}


});


</script>


<div id="uitkomst"></div> /**** Where I want the page to load ****/



Statuten is the value of the first button.

When I test with alert($deel); it gives the right value but on click it shows the page to insert for about 1 second, sometimes it works when I dubble click.

I am searching the web for a week now and cannot find the answer I need.

any ideas??

it's hard to explain because of my poor english and i am a newbie to jquery and php.

rubyOnPails
11-26-2016, 01:54 AM
Hey did you try this? Let me know if this doesn't work.


$(document).on("click",".item", function() {
var $deel = $(this).text();
if ( $deel == "Statuten"){
$('#uitkomst').load('statuten.php');
}
});

Bicklo
11-26-2016, 10:58 AM
Thank you for your reply, still the same problem showing the loaded page for 1 second on click and then nothing.

I am sure it has to do with php but don't know what.

jscheuer1
11-26-2016, 03:13 PM
One problem is that the link is executing normally. An href of "" means reload the page. To stop that:


$(document).on("click",".item", function(e) {
var $deel = $(this).text();
if ( $deel == "Statuten"){
$('#uitkomst').load('statuten.php');
e.preventDefault();
}
});

which will prevent the link from executing only when loading the external page. If you want all .item links to not fire normally, do it like so:


$(document).on("click",".item", function(e) {
var $deel = $(this).text();
if ( $deel == "Statuten"){
$('#uitkomst').load('statuten.php');
}
e.preventDefault();
});

There could still be other problems.

Bicklo
11-26-2016, 03:48 PM
Thank you sir, you did it, a 14 day headache finaly over.

Thank you so much!!