dtmwnqng38644 2014-01-21 04:10
浏览 94

如何在同一页面中将值从javascript传递到php

Im tying to implament a preloader for swf based on this Post, but im getting trouble passing the javascript value to a php variable.

     <script type="text/javascript">

        var swfJSPreLoaderConfig = {

         'assets':['swf/test.swf'],

            'assetLoaded': function( asset){

             alert(asset);

            },}

    </script>

The alert in the above code shows only when the swf file test.swf is fully downloaded. the value that im trying to get in php is asset ( this value contain the swf file path, in this example is swf/test.swf. the alert fires always when the swf files is fully dowloaded and it works very good.)

i tried something like this to get it in a php variable. but no lucky.

$filename = $_REQUEST['asset'];

also i tired using ajax but nothing.

    <script type="text/javascript">

     var swfJSPreLoaderConfig = {

       'assets':['swf/test.swf'],

         'assetLoaded': function( asset){   

                $.ajax ({ 
                type: "post",
                url: "index.php",
                data: { 'asset': asset },
                success: function()
                    {
                        alert(asset);
                    }
                });

            },}

    </script>

and then

 $filename = $_REQUEST['asset'];

Whats worng?

  • 写回答

2条回答 默认 最新

  • doubao6936 2014-01-21 04:12
    关注

    Try this,

    data: { 'asset': asset },
    success: function(response)
         {
            alert(response);
         }
    

    instead of,

      data: { 'asset': asset },
      success: function()
            {
              alert(asset);
            }
      });
    

    PHP:

     echo $filename = $_REQUEST['asset'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作