Pass a variable value from javascript value to php variable [duplicate] - javascript

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 8 years ago.
I would like to pass a text string to a php file,
Here is my code:
var t2 = new Text(figure_defaultFigureTextStr, x, y + figure_defaultFigureRadiusSize/2,
figure_defaultFigureTextFont, figure_defaultFigureTextSize);
t2.style.fillStyle = figure_defaultFillTextStyle;
f.addPrimitive(t2);

Basically PHP is a server side language, you cannot execute it client-side.
So the best bid would be, to send a HttpPost request alongwith the variable value. This would send the data to the server. There you can save the data of it inside a file or what so ever.

Related

Pass a variable from JS to PHP for MYSQL query without ajax [duplicate]

This question already has answers here:
How do I pass JavaScript variables to PHP?
(16 answers)
How can I use a JavaScript variable as a PHP variable? [duplicate]
(7 answers)
Closed 11 months ago.
Hi I need to pass a JS variable to PHP that can be used in a MYSQL query
i tried with
$varPQR = "<script> document.writeln(IdLocalStorage); </script>"; echo $varPQR;
$queryGetPqr = "SELECT * FROM {$wpdb->prefix}sfcwp_pqrs WHERE codigo_queja = {$varPQR}";
didn't work
Use form and hidden input to pass data from client to server

Retrieving Javascript variable into Php code from empty div tag [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 2 years ago.
1. <script>
2. document.getElementById('description').innerHTML = description;
3. </script>
4. <div id="description"></div>
How to get the value of line 4 into PHP code?. Also when I use the traditional way
<?php $weather = <div id = "description"></div>?>
The weather variable is not displayed wherever I want it to be displayed.
Any help is greatly appreciated. Thank You.
The PHP is processed on the server side, while the Javascript value is processed in the user's browser. So when the page is sent, there is no value there yet.
You can do this:
<?php
$weather = '<div id="description">Details go here</div>'; // define variable
echo $weather; // include / print variable
?>
But if the value does not exist yet that you want to include, then you need to use AJAX to send it to PHP if that's indeed what you need. Although if it doesn't need to go back to the server, it can likely be done just with JavaScript on the client side.
I suggest finding some good books on learning PHP / learning JavasScript / learning HTML.

Passing js variable to laravel model [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Accessing $_COOKIE immediately after setcookie()
(9 answers)
Closed 3 years ago.
I am creating ajax model update request, after this I want to refresh my compacted variable with ajax response. I need to do these tasks without page reload. If anyone have any ideas please share with me.
My code:
success: function(result) {
console.log(result);
var abc = JSON.stringify(result);
Cookies.set('clients', abc, 10);
$('#cookie').html(Cookies.get("clients"));
var abc2 = $('#cookie').text();
<?php $client1 = $_COOKIE['clients']?>
I have been trying to do it with cookies, but as I know, to get recent cookies need reload page.

I need to get jquery this.val() value into PHP at runtime [duplicate]

This question already has answers here:
Access a JavaScript variable from PHP
(9 answers)
What is the difference between client-side and server-side programming?
(3 answers)
Closed 5 years ago.
Is there a way to get the jquery this.val() read into PHP at runtime?
I have a dynamic push of data and need to run a SQL statement that depends on the jquery value of this.val() - so something like
<?php $sql = "select * from table where id = " . this.val(); ?>
No, becouse PHP can't read user's DOM.
You need to make an ajax request to send the data to the server.
jquery.ajax

How to Put Jquery Variable into PHP Variable? [duplicate]

This question already has answers here:
How do I pass JavaScript variables to PHP?
(16 answers)
Closed 8 years ago.
<script>
myjsvar= $('#project_start_date').val(); //result is 10-11-2014
</script>
<?php
$myphpvar = //how to get value of myjsvar into php variable?
?>
how to get value of myjsvar into php variable $myphpvar?
thanks
You can't use javascript variable in php code. Php code run's on the serverside and javascript code runs in the client side. You can't ask the browser to run php code.
Your variable loc will have a value only when the code reaches the browser.
If you want to get some value from server and combine it with javascript variables then do the following.
Use an ajax request and send the desired values to server. The server will return with a response. Use that response text and store it in your action variable.

Categories

Resources