变量x获取当前网址。我需要把这个url放到xxxx所在的位置。我该怎么做呢?
<script type='text/javascript'>
function postListen()
{
var x = ( document.URL );
FB.api(
'/me/beatmushroom:listen',
'post',
{ song: xxxx},
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Listen was successful! Action ID: ' + response.id);
}
});
}
答案 0 :(得分:2)
只需在对象文字中使用该变量即可。虽然键总是一个字符串(即使没有引号),但值可以是任何JavaScript epxression:
{ recipe: x },
答案 1 :(得分:1)
只需将'xxxx'
替换为变量x
function postCook() {
var x = ( document.URL );
FB.api(
'/me/[YOUR_APP_NAMESPACE]:cook',
'post',
{ recipe: x },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
}
);
}