5 Replies - 358 Views - Last Post: 26 November 2016 - 08:54 AM

#1 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Trying to insert page in a div with .load on jquery

Posted 24 November 2016 - 01:29 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>'; 
    

}
    

?> 




Javascript code

<script type="text/javascript">
      
         
 $(".keuze").on('click', '.item', function(){
  
            
    var $deel = $(this).text();
     
  if ( $deel == "Statuten"){
    
        
    $('#uitkomst').load('statuten.php');
    
}
   
 
});   
      

</script>




html

<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??

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to insert page in a div with .load on jquery

#2 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,910
  • Joined: 12-December 12

Re: Trying to insert page in a div with .load on jquery

Posted 24 November 2016 - 01:57 PM

You should not be using the mysql extension for any new code, it is obsolete in PHP. See my signature below. Nor is there an align-left attribute.

Where do you place the alert?
Are there errors in your browser's console?
If the page reloads, then is your button a submit button? In which case you would need to cancel its default behaviour of submitting a form.
Was This Post Helpful? 1
  • +
  • -

#3 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Re: Trying to insert page in a div with .load on jquery

Posted 24 November 2016 - 11:29 PM

Thank you for your reply I will test with mysqli.


For the alaert I replaced

<script type="text/javascript">
      
         
 $(".keuze").on('click', '.item', function(){
  
            
    var $deel = $(this).text();
     
  if ( $deel == "Statuten"){
    
        
    $('#uitkomst').load('statuten.php');
    
}
   
 
});   
      

</script>




with

<script type="text/javascript">
      
         
 $(".keuze").on('click', '.item', function(){
  
            
    var $deel = $(this).text();
     
 alert($deel);
   
 
});   
      

</script>



and it gives met 'Statuten' witch is good.

On button click I just want to open a other php page ( without Html, Body ) in a div.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,910
  • Joined: 12-December 12

Re: Trying to insert page in a div with .load on jquery

Posted 25 November 2016 - 04:22 AM

You didn't answer my other two questions.

I would start by testing with loading simple html content, from a .html file, then move to .php content.

For .php content I would first return "hello", before initiating any database code.

Progressive Testing

Also check that $deel doesn't contain any additional characters such as whitespace, easiest to do by checking its length.
Was This Post Helpful? 1
  • +
  • -

#5 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Re: Trying to insert page in a div with .load on jquery

Posted 25 November 2016 - 10:44 AM

No errors in my browser's console

Same with html works perfect My link ( free webspace )

I have a look at the link you provided.

Thank you
Was This Post Helpful? 0
  • +
  • -

#6 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Re: Trying to insert page in a div with .load on jquery

Posted 26 November 2016 - 08:54 AM

I finaly foud the answer to my problem ( well I didn't find it someone else did).

If it can be of any help for others here's the answer.


javascript

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



andrewsw thank you for helping!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1