简体   繁体   English

用ajax传递JavaScript值到PHP变量

[英]Passing Javascript value to PHP Variable using ajax

I am trying to use a Flash detection script to assess whether Flash Plugin is enabled in the user browser so that a different page loads. 我正在尝试使用Flash检测脚本来评估是否在用户浏览器中启用了Flash插件,以便加载其他页面。 The Flash detection script is as follows, using jquery 1.8.2 and jquery.jqplugin 1.0.2 Flash检测脚本如下,使用jquery 1.8.2和jquery.jqplugin 1.0.2

<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="jquery.jqplugin.1.0.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("#withflash").hide();
    $("#noflash").hide();
    if ($.browser.flash == true)
      $("#withflash").show ();
    else
      $("#noflash").show ();
});
</script>
<div id="withflash">Flash Supported</div>
<div id="noflash">Flash Not Supported</div>

I get the display that "Flash Supported" if Flash Plugin is present.. I need to capture the value whether flash plugin value is true in a php variable $hasFlashSupport as below: 如果存在Flash Plugin,我将得到显示“ Flash Supported”的信息。我需要捕获一个PHP变量$hasFlashSupport flash插件值是否为true的值,如下所示:

<?php
echo " $hasFlashSupport";
exit;
?>

I am aware that PHP is server based and Javascript is client based.. Hence Ajax would be a nice option to capture the javascript variable to my php variable. 我知道PHP是基于服务器的,而Javascript是基于客户端的。因此,Ajax将是一个很好的选择,可以将javascript变量捕获到我的php变量中。 I am totally ignorant about Ajax syntax and how to achieve it. 我对Ajax语法及其实现方式一无所知。

Request the experts here to help me out with the code on how this can be achieved... Thanking all of you in advance.. 请这里的专家为我提供有关如何实现此目标的代码。在此先感谢大家。

您可以使用具有getElementById方法的DOMDocument对象来实现。

Try this: 尝试这个:

if true 如果属实

<div id="withflash">
    <?php echo '$hasFlashSupport'; ?>
</div>

else 其他

<div id="noflash">
    <?php echo '$hasFlashSupport'; ?>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM