Echo variable from JS to HTML / PHP
Echo variable from JS to HTML / PHP
hykl
Posts: 48Questions: 19Answers: 5
I want to ask how to take the value of the variable id from Ajax datatables and show value in PHP or HTML? For example: I datatables ajax and everything works without problem using JS file. But I just want to take the value of the JS file in HTML or PHP? It is possible and ask for help.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You want to send a value (variable) to the server on Ajax data load requests? If so, use
ajax.data
. If I've misunderstood, could you clarify your question please.Allan
No, I want get value from ajax in file JS and in file PHP i want echo print value, you understand? Or I have to paint for idea?
I'm afraid I still don't understand. Could you please link to an example of what you want to do.
Allan
OK, I write now for understand:
And how get value from $result_raw for echo print in file PHP?
file index.php:
Why variable $result_raw does not echo? Problem?
You have two different scripts there:
The two scripts are entirely independent - you can't use a variable from one in the other, without linking them.
I would suggest you simply do something like:
```html
<?php > ``` ?><!DOCTYPE html>
...
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
editor = new $.fn.dataTable.Editor({
ajax: "../editor/examples/php/staff.php",
table: "#example",
})
});
</script>
<body>
<?php
$RAW_SQL_QUERY="SELECT COUNT(id) FROM tablename;
$result_raw = $db ->sql($RAW_SQL_QUERY)->fetchAll();
Note: THIS WILL NOT WORK WITHOUT EDITING! You are using the Editor
$db
library, which you can do, but you would need to include theDataTables.php
file in your index.php file. Alternatively, make your own MySQL database connection. Any PHP tutorial will show you how to do that.Allan
This is resolved :-)
Thank you