I need help to modify this script. This JPlayer script gets its URL data from a getsong.php file which it works fine, but I need send a string value back to the getsong.php file, like example:
getsong.php?rock
or
getsong.php?pop
I need to send this string value "?" using these "OnClick" links:
<a href="#" onclick="new_string('code=rock')">Rock</a>
<a href="#" onclick="new_string('code=pop')">Pop</a>
This is the current jplayer script:
<script type="text/javascript">
var dataString_code
$(function() {
$(".new_string").click(function() {
var code = $("#code").val();
dataString_code = 'code='+ code;
return true;
});
});
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () {
var data = $.ajax({
url: "getsong.php?"+ dataString_code,
async: false
}).responseText;
string = data.split('|');
$(this).jPlayer("setMedia", {
mp3: string[0]
}).jPlayer("play");
$('ol#artist').html(string[1]);
$('ol#songname').html(string[2]);
},
ended: function (event) {
var data = $.ajax({
url: "getsong.php?"+ dataString_code,
async: false
}).responseText;
string = data.split('|');
$(this).jPlayer("setMedia", {
mp3: string[0]
}).jPlayer("play");
$('ol#artist').html(string[1]);
$('ol#songname').html(string[2]);
},
swfPath: "js",
supplied: "mp3"
});
});
</script>
PLEASE HELP
Thanks.
Haha, okay: You are calling your function onclick="new_string('code=rock')" which triggers the execution of a function. Perfect. But this function is not defined, e.g.
var new_string = function(ev) {
}
instead you are using: $(".new_string").click(function() { which would attach a new onClickHandler to an non - existing element (you are using the class - selektor of jQuery ".classname" and as far as I can see it, there is no element having the class "new_string". So you can either:
<a href="#" class="new_string">Rock</a>
$(".new_string").click(function() {
var oThis = $(this); // this points to the "a" - DOM - element
var code = oThis.html();
dataString_extra = 'code='+ code;
return true;
});
or
<a href="#" onclick="new_string('code=rock')">Rock</a>
var new_string = function(code) {
dataString_extra = code;
return true;
}