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)?
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
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):
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]; ?>