私はユーザーからのログイン変数を使用するhtml/php複合文書を持っています。 (これは、サインイン上の別のphpファイルから来た):phpファイルからjsファイルにphp変数を渡すには?
<html> Welcome <?php echo $login; ?> </html>
//Now when the user uses the chatbox, and clicks send, I would like to pass the data (inclusive of the username) from this html file to the .js so it can in turn pass onto another php file. (ps I tried the following but to no avail, as the .js file is external to the html/php composite):
$("#newMsgSend").click(function()//triggers script to send the message
{
$("#newMsgCnt").val(''); // clears the box when the user sends a message
var username = "<?php echo $login; ?>";
alert(username);
});
どこから$ loginを取得しますか?それはどこに割り当てられていますか?どのように最初の場所でHTMLページに渡されますか? – shamsup
グローバルスコープで 'var username'を使うことはできません。入れ子になっているjQuery関数の中からそれを削除するだけですか? – Rasclatt
私が送信した瞬間に警告が表示される<?php echo $ login; ?>をユーザ名として使用します。私はそれが変数を読んでいないことを知っています。 –