0

变量 x 正在获取当前 url。然后我需要把这个 url 放到 xxxx 所在的位置。我该怎么做呢?

<script type='text/javascript'>
      function postListen()
       {
    var x = ( document.URL ); 
          FB.api(
            &#39;/me/beatmushroom:listen&#39;,
            &#39;post&#39;,
            { song:  xxxx},
            function(response) {
               if (!response || response.error) {
                  alert(&#39;Error occured&#39;);
       } else {
          alert(&#39;Listen was successful! Action ID: &#39; + response.id);
       }
    });

}

4

2 回答 2

2

只需在对象文字中使用变量。虽然键始终是字符串(即使没有引号),但值可以是任何 JavaScript 表达式:

{ recipe: x },
于 2012-05-13T10:27:48.093 回答
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);
           }
        }
    );
}
于 2012-05-13T10:27:37.583 回答