How to `GET` php file and print response to table body?

Hi
I have a table:

<script
 src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script>
                  $.ajax({
  url: 'http://192.168.1.146/test.php',
  type: 'GET',
  dataType: 'html',
  data: content,
}).done(function ( data ) {
  $('#tbody').append(data);
});
                  </script>

<table>
<tbody id="tbody">
//php response here
<tbody>
<table>

And a test.php that echos:

<tr>
//content
</tr>

So I need some sort of ajax that will make a get requst and return the result to tbody as my one does not work.

How can I do this?

UPDATE: for some reason this code opens random dialogue boxs than tries to print the page!
Thanks in advance.

This line throws an uncaught exception error in the developer console:

  data: content,

because you’re using an undefined variable content. I changed that line to read

data : "test=parameter",

and it works for me. The table gains an extra row if I echo the get parameter:

<?php
//var_dump($_GET);
echo "<tr><td>1</td><td>". $_GET['test'] . "</td></tr>";
?>
1 Like

Innitially put the script at the bottom of the body inside in $(document).ready() function.

Thanks it works now!
firefox was showing:

Scripts may not close windows that were not opened by script.  jquery-2.2.4.min.js:4:14039
TypeError: Not enough arguments to Window.showModalDialog.[Learn More]  jquery-2.2.4.min.js:4:14040
	n.param/e http://code.jquery.com/jquery-2.2.4.min.js:4:14040
	Gb http://code.jquery.com/jquery-2.2.4.min.js:4:13925
	n.param http://code.jquery.com/jquery-2.2.4.min.js:4:14286
	.ajax http://code.jquery.com/jquery-2.2.4.min.js:4:10380
	<anonymous> http://192.168.1.146:85/email#:581:19
	n.Callbacks/i http://code.jquery.com/jquery-2.2.4.min.js:2:27146
	n.Callbacks/j.fireWith http://code.jquery.com/jquery-2.2.4.min.js:2:27914
	.ready http://code.jquery.com/jquery-2.2.4.min.js:2:29705
	J http://code.jquery.com/jquery-2.2.4.min.js:2:29890

but chrome got it right

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.