0

I need a little hand here, both this javascript functions are working properly, but I need a value from the first script, so I can "POST" it, but I can't figure out how to make the (string[3]) value to show on the second script and therefore use it.

The only function of this first script is to get values from the getsong.php file

<script type="text/javascript">
var string[3]{
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
    ready: function () {
        var data = $.ajax({
          url: "getsong.php",
          async: false
         }).responseText;

         string = data.split('|');
        $(this).jPlayer("setMedia", {
            mp3: string[0]
        }).jPlayer("play");

        $('ol#one').html(string[1]);
        $('ol#two').html(string[2]);
        $('ol#three').html(string[3]);

    },
    ended: function (event) {  
        var data = $.ajax({
          url: "getsong.php",
          async: false
         }).responseText;

         string = data.split('|');
        $(this).jPlayer("setMedia", {
            mp3: string[0]
        }).jPlayer("play");


        $('ol#one').html(string[1]);
        $('ol#two').html(string[2]);
        $('ol#three').html(string[3]);

    },
    swfPath: "js",
    supplied: "mp3"

});
});

Then the only function is second script to post to the "update_db.php" with a value from (string[3]) from the script above, and also is reloading the page at the same time. I need the value in the 'STRING[3] GOES HERE' area.

$(function() {
$("#submit01").click(function() {
var song_id = $("#song_id").val();
var dataString = 'song_id='+ 'STRING[3] GOES HERE';

if(song_id=='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "update_db.php",
data: dataString,
success: function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);","0");
}
});
}
return false;
});
});


/////
}

</script>
1
  • You have a syntax error on the second line of your code var string[3]{ Commented Dec 13, 2013 at 20:16

2 Answers 2

1

Place var string above the line:

$("#jquery_jplayer_1").jPlayer({

And remove var from

 var string = data.split('|');

You can now access string in any function you want.

Sign up to request clarification or add additional context in comments.

2 Comments

Still not working :( can you check the changes above?
What are you doing here..? var string[3]{ Simply delcare var string; Split it when you need, and use string[3] the same way you did
0

You can make it a global variable by adding something like the following at the top of your page:

<script>
    var str3 = '';
</script>

Set the value of str3 in your first function and then access it in the latter.

Comments

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.