Facebook API 返回 null,如何在 Javascript 中跳过它
如果没有返回空值,则此代码可以很好地工作。但我在测试过程中注意到,如果任何值为空,则会抛出错误并破坏脚本的其余部分。
如果为空,我如何跳过该值,或将其设置为其他值。
function fqlQuery(){
FB.api('/me', function(response) {
var query = FB.Data.query('SELECT uid, first_name, last_name, email, sex, pic_square, timezone, birthday_date, current_location FROM user WHERE uid = me()', response.id);
query.wait(function(rows) {
fb_uid = rows[0].uid;
first_name = rows[0].first_name;
last_name = rows[0].last_name;
sex = rows[0].sex;
email = rows[0].email;
fb_pic_square = rows[0].pic_square;
timezone = rows[0].timezone;
birthday_date = rows[0].birthday_date;
current_city = rows[0].current_location.city;
current_country = rows[0].current_location.country;
$.ajax({
type: "POST",
url: "postdb.php",
data: "first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&fb_uid=" + fb_uid + "&sex=" + sex + "&fb_pic_square=" + fb_pic_square + "&timezone=" + timezone + "&birthday_date=" + birthday_date + "¤t_city=" + current_city + "¤t_country=" + current_country,
success: function(msg){
alert( "Data Saved: " + msg );
}
});
});
});
提前致谢。
This code work great if there are no null values returned. But I noticed during testing that if any value is null then it throws and error and breaks the rest of the script.
How can i skip the value if null, or set it to something else.
function fqlQuery(){
FB.api('/me', function(response) {
var query = FB.Data.query('SELECT uid, first_name, last_name, email, sex, pic_square, timezone, birthday_date, current_location FROM user WHERE uid = me()', response.id);
query.wait(function(rows) {
fb_uid = rows[0].uid;
first_name = rows[0].first_name;
last_name = rows[0].last_name;
sex = rows[0].sex;
email = rows[0].email;
fb_pic_square = rows[0].pic_square;
timezone = rows[0].timezone;
birthday_date = rows[0].birthday_date;
current_city = rows[0].current_location.city;
current_country = rows[0].current_location.country;
$.ajax({
type: "POST",
url: "postdb.php",
data: "first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&fb_uid=" + fb_uid + "&sex=" + sex + "&fb_pic_square=" + fb_pic_square + "&timezone=" + timezone + "&birthday_date=" + birthday_date + "¤t_city=" + current_city + "¤t_country=" + current_country,
success: function(msg){
alert( "Data Saved: " + msg );
}
});
});
});
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
rows[0].foo
为 null,将返回""
(空字符串)。will return
""
(an empty string) ifrows[0].foo
is null.我是这样修好的。
I fixed it like this.