How to display the result in the midle coloumn?

Discussion in 'PHP' started by acepsdr, Oct 22, 2009.

  1. #1
    I have small application to display data in html file from php file. I have 3 file:

    DATA.PHP
    <?php echo "This is must to show in the midle"; ?>
    Code (markup):

    EXTERNAL.JS
    var userid;
    $(document).ready(function(){
    $.get("data.php", { id: userid }, function(data){
    $('body').append(data);
    });
    });
    
    Code (markup):


    INDEX.HTML
    <html>
    <head>
    <script src="jquery.js" type="text/javascript"></script>
    </head>
    <body>
    <table width="100%" border="1" >
      <tr>
        <td>This document in the first (left) coloumn, example for this case. </td>
        <td>
          <script src="external.js" type="text/javascript"></script>	</td>
        <td>This document in the first (left) coloumn, example for this case. </td>
      </tr>
    </table>	
    </body>
    </html>
    Code (markup):

    But if I running this html file (index.html), the result not show in the column on table, but result show outside table (at the bottom page). How can display result in the midle coloumn on the table (location script to show result)?
     
    acepsdr, Oct 22, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    where exactly in html do you want to display the text retrieved from data.php?

    If it has to come where you have included the javascript then better way is to include javascript at bottom of page. and assign an ID to an element preferably DIV or SPAN inside the TD and instead of $('body').append(data); use $('#ID').html(data);

    Something like this..

    EXTERNAL.JS

    INDEX.HTML

     
    mastermunj, Oct 22, 2009 IP
  3. acepsdr

    acepsdr Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, thanks very much.
     
    acepsdr, Oct 22, 2009 IP
  4. acepsdr

    acepsdr Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I wand sending value from html file, example like this:

    
    <script type="text/javascript">
    [COLOR="Red"]  var var1 = "13";
      var var2 = "tested";[/COLOR]</script>
    
    <script src="jquery.js" type="text/javascript"></script>
    <script src="external.js" type="text/javascript"></script>
    
    Code (markup):

    How the script in the external.js if sending more then one value?
    $(document).ready(function(){
    [COLOR="red"]$.get("data.php", { id: var1}, function(data){[/COLOR]$('body').append(data);
    });
    });
    Code (markup):
     
    acepsdr, Oct 23, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    You can refer following link for more details..

    http://docs.jquery.com/Ajax/jQuery.get
     
    mastermunj, Oct 23, 2009 IP
  6. acepsdr

    acepsdr Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I try change data.php file like below, but the var1 and var2 can't read (blank value).

    data.php
    <?php echo "This is must to show $_GET[id] in the midle of ". $_GET[name]; ?>
     
    acepsdr, Oct 26, 2009 IP