我想知道是否有人可以帮助解决我遇到的这个问题.
我整个上午都在尝试使用Facebook共享按钮来处理当时正在页面上播放的视频所特有的动态参数.
我认为以下应该可以工作,但我收到错误:share_title未定义.
然后我尝试将div的内容设置为ajax响应的内容,然后将params变量设置为该div的内容,以便变量可以在FB.ui函数内访问,但似乎也不起作用.
有没有人有任何想法?
$('.share_button').live('click', function(e){
$('#player').fadeOut('slow');
var share_id = $(this).attr('id');
$.ajax({
type: 'GET',
url: '/youtube.php',
data: 'share='+ share_id,
success: function(data) {
//$('#params').html(data);
//params = $('#params').html();
param = data.split('--');
share_title = param[0];
share_description = param[1];
share_picture = param[2];
share_views = param[3];
}
});
e.preventDefault();
FB.ui(
{
method: 'feed',
name: share_title,
link: 'http://www.facebook.com',
picture: share_picture,
caption: share_views,
description: share_description
},
function(response) {
$('#player').show('slow');
});
});
Run Code Online (Sandbox Code Playgroud) 似乎是愚蠢的问题,但只是好奇.
num = "hello";
alert(num);
Run Code Online (Sandbox Code Playgroud)
为什么这可能我没有在这里初始化num变量.
num = "hello";
Run Code Online (Sandbox Code Playgroud)
代替
var num = "hello";
Run Code Online (Sandbox Code Playgroud) 即使我使用命名空间,函数名也是混合的.在下面的例子中,当我打电话 nwFunc.callMe()或者$.Test1.callTest()它会执行_testFunction()的doOneThing.我预期$.Test1.callTest()调用_testFunction()的$.Test1API,而不是之一doOneThing.我需要做些什么来纠正它?
例:
var doOneThing = function() {
_testFunction= function() {
...
}
return {
// public
callMe: function(){
_testFunction();
}
}
}
var nwFunc = doOneThing();
nwFunc.callMe();
$.Test1.callTest();
Run Code Online (Sandbox Code Playgroud)
jQuery.Test1 = (function(){
_testFunction= function() {
...// do differently
}
return {
// public
callTest: function(){
_testFunction()
}
}
}(jQuery))
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的自制API,该API读取服务器上某些文件的内容,解析它们并以JSON发送它们的内容。
我的网页使用Ajax调用API,读取数据并将其存储在自定义对象上。问题是,无论我在JSON中解析了多少文件,Javascript代码都只处理第一个文件。
runs = [];
function Solution(values) {
this.number = values[0]
this.weight = values[1]
this.value = values[2]
this.score = values[3]
}
function DateValue(date) {
regex = new RegExp(/(\d{4})-(\d{1,2})-(\d{1,2})-(\d{1,2}):(\d{1,2}):(\d{1,2})-(\d{1,2})/)
dateArray = date.split(regex)
this.year = dateArray[1]
this.month = dateArray[2]
this.day = dateArray[3]
this.hour = dateArray[4]
this.minutes = dateArray[5]
this.secondes = dateArray[6]
}
function Run(values) {
this.algorithm = values["log"]["Algorithm used"]
this.weight = values["log"]["Weight"]
this.value = values["log"]["Value"]
this.date = new DateValue(values["log"]["Date"])
this.solutions = []
for(i = 0; i < values["datas"].length; i++) {
this.solutions.push(new Solution(values["datas"][i])) …Run Code Online (Sandbox Code Playgroud)