How to assign the javascript variable value to php variable [duplicate]

2024/2/27 7:11:45

Possible Duplicate:
How to pass JavaScript variables to PHP?

I want to assign the javascript variable to php variable

$msg = "<script>document.write(message)</script>";
$f = new FacebookPost;
$f->message  = $msg;

But it is not working......

Answer

PHP is executed before javascript. You can't do that. PHP is server based, JavaScript is client based.

When PHP is finished executing, it outputs HTML. In the HTML there can be JavaScript code also. So PHP can 'control' JavaScript by outputting JavaScript code to the page, but not the other way around. You'd have to use Ajax-call for that.

http://en.ppmy.cn/q/42339.html

Related Q&A

Facebook Connect Dialog Popup

When using the "Connect" facebook connect button, when I click it, it opens up a new popup window outside of the current window. This is quite annoying, how am I able to use the inline modal …

how to optimize this javascript code?

How to optimize this functions? Can I make one function for all operations?$(#b-hat1).click(function() {$(#hat3).hide();$(#hat2).hide();$(#hat1).show();});$(#b-hat2).click(function() {$(#hat3).hide()…

How to client-side detect when a page is bookmarked?

Is it possible to detect when a page is bookmarked within the browser, using Javascript?

Jquery File Tree - how to return folder name on folder click

I have installed and trying to customize Jquery File Tree so that, on click of folder name, the folder name and path are returned to the calling function. Currently it only expands and collapses folder…

Using variables inside react native stylesheets wont recognize the variable

I import a color as props.color into my functional component and set it as the state tagColor. When I use tagColor as a value in my stylesheet to set the background color i receive the error variable t…

Invisible reCAPTCHA sending empty g-recaptcha-response with multiple forms

I am trying to use Google Invisible reCAPTCHA, but it is sending empty the g-recaptcha-response POST parameter when i have multiple forms in the same page. Here is my code:Google JS<script src="…

How to properly catch errors in promises?

I am under the impression that these two things are not equivalent:return somePromise().then().then().then().catch(function(e) { throw e; });andreturn somePromise().catch(function(e) { throw e; });.the…

Any difference between React.Component and Component?

I have seen two ways of accessing Component:import React from react;class Foo extends React.Component {... }andimport React, { Component } from react;class Foo extends Component {... }Is there any diff…

Suppress proxy generation for some hubs or methods

Im starting out with SignalR and I have a situation where Im going to have a SignalR site that will be broadcasting messages to clients, but I also need an admin interface that will actually trigger th…

What is the equivalent of web.config for JavaScript code?

What is the equivalent of the .NET web.config for JavaScript code?Im getting to grips with the use of the configuration details in the web.config file, but I dont know what (or even if) the configurat…