0

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 Answers 2

1

Try this,

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

instead of,

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

PHP:

 echo $filename = $_REQUEST['asset'];
Sign up to request clarification or add additional context in comments.

9 Comments

Create new page assets.php in that page you add this echo $filename = $_REQUEST['asset']; and update that page name in $.ajax url parameter!
the alert shows the value of asset but no echo of variable
Yes, it should print the value of the asset.
thank your for your help but after doing all the steps you requested no echo of echo $filename = $_REQUEST['asset']; in index.php . im getting mad now.
Things are, You can't pass the javscript value into php variable, using ajax you can embed the php output into html using some selector.
|
0

Change from

url: "index.php"

to

url: "index.php?asset="+asset

Then in PHP, use:

echo $_GET['asset'];

to confirm that you are sending the correct value

2 Comments

why do you want to change the POST method to GET ?
Didn't see that he was sending it in the data field. Then his code was already working, except that he didn't use an echo to see it. Also the alert should be using the value from the callback, not the original asset value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.