{ bracket is closed properly but firebug complains about it

  • Thread starter knowledgenotebook
  • Start date
K

knowledgenotebook

May I borrow your eyes for it?

What I want to do is to post a short text to my FB wall. Thanks.

<html>
<head>
<script src="http://connect.facebook.net/en_us/all.js"></script>
<script type="text/javascript">

FB.init({appid: '100001125873988', status: true, cookie: true,xfbml:
true});


function shareonWall() {
FB.getLoginStatus(function(response){
if (response.session) {
FB.ui ({
method: 'stream.publish',
message: '',
attachment: {
name: 'Don',
caption: 'Communication 303',
description: ('Clarity, brevity and an understanding of your
audience.'),
href: ''
}
function (response) {
if (response && response.post_id)
{
alert('The note is published to your FB wall now.');
}
};

});
}
else
{
alert('Please log in to FB first prior to posting.');
}

})
}

</script>
</head>

<body>
<input type="button" value="Share" onClick="shareOnWall()"/>
</body>
</html>
 
G

Gregor Kofler

Am 2011-04-01 06:50, knowledgenotebook meinte:
May I borrow your eyes for it?

What I want to do is to post a short text to my FB wall. Thanks.

[source and markup snipped]

And the question is?

Anyway, I'm pretty sure that Firebug tells you *where* in your code it
misses the curly bracket. Besides, the various JS lints floating around
will also tell you where they miss the bracket in question [1].
Finally, when posting such "questions", make sure that your source is
readable. Your indentation sucks (you can leave out the markup, too),
and keeps people from risking a seconds look.

Gregor


[1]
Problem at line 13 character 5: Expected '}' to match '{' from line 4
and instead saw 'function'.
 
K

knowledgenotebook

Am 2011-04-01 06:50, knowledgenotebook meinte:
May I borrow your eyes for it?
What I want to do is to post a short text to my FB wall.  Thanks.

[source and markup snipped]

And the question is?

Anyway, I'm pretty sure that Firebug tells you *where* in your code it
misses the curly bracket. Besides, the various JS lints floating around
will also tell you where they miss the bracket in question [1].
Finally, when posting such "questions", make sure that your source is
readable. Your indentation sucks (you can leave out the markup, too),
and keeps people from risking a seconds look.

Gregor

[1]
Problem at line 13 character 5: Expected '}' to match '{' from line 4
and instead saw 'function'.

--http://vxweb.net

Yeah, I used firebug, sorry, forgot to post the exact err msg, it was
and still is on my ff3.6 and firebug 1.6.2:
"
missing } after property list
[Break On This Error] function (response)
"
Line 52

Why do we get different err msg?

And according to the debugging info from yours, is the following js
construct faulty (rusty on this guy now..),

FB.getLoginStatus(function(response){
...
function(response)
{
...
}
})

Thanks.
 
K

knowledgenotebook

Seconded. With proper indentation, the problem would have been obvious
at a glance.
Problem at line 13 character 5: Expected '}' to match '{' from line 4
and instead saw 'function'.
missing } after property list
[Break On This Error] function (response)
Why do we get different err msg?

Your error message is from Firebug, Gregor's is from JSLint (I assume).
And according to the debugging info from yours, is the following js
construct faulty (rusty on this guy now..),
FB.getLoginStatus(function(response){
  ...
  function(response)
  {
  ...
  }
})

No, that's not the problem. What you did was, simplified -

    FB.ui({
        method: 'stream.publish',
        message: '',
        attachment: {
            name: 'Don',
            href: ''
        }
        function (response) {
            // code
        };
    });

That is, you put the callback function right in the middle of the object
literal. That's a syntax error. What you meant was -

    FB.ui({
            method: 'stream.publish',
            message: '',
            attachment: {
                name: 'Don',
                href: ''
            }
          },
          function (response) {
              // code
          }
    );

That's syntactically correct but still not very readable. If your
statements get so long and convoluted that you can't even spot syntax
errors anymore, you can use temporary variables to improve readability:

    var fbOpts = {
        method: 'stream.publish',
        message: '',
        attachment: {
            name: 'Don',
            href: ''
        }
    };
    var callback = function (response) {
        // code
    };
    FB.ui(fbOpts, fbCallback);

Thanks, stepfan, very helpful.

But now I'm getting the following err msg:
FB is not defined
[Break On This Error] FB.init({appid: '100001125873988', status: true,
cookie: true,xfbml: true});

How come?
 
T

Thomas 'PointedEars' Lahn

Stefan said:
knowledgenotebook said:
But now I'm getting the following err msg:
FB is not defined
[Break On This Error] FB.init({appid: '100001125873988', status: true,
cookie: true,xfbml: true});

How come?

URLs are case sensitive.

Wrong. Some parts of URLs (generalized: URIs) are case-sensitive, others
(like the domain-part) are not. Whether a part of a URL is case-sensitive
depends on the server-side operating system, filesystem, URL rewrites, and
the target resource. See also RFC 3986.


PointedEars
 
K

knowledgenotebook

But now I'm getting the following err msg:
FB is not defined
[Break On This Error] FB.init({appid: '100001125873988', status: true,
cookie: true,xfbml: true});
How come?

URLs are case sensitive. Check that URL you used for the Facebook API
script (just open it in a browser)...

ok, probably someone at FB is play April Fool trick here with the URL,
I'm using the 'correct' one now.

Ok, my current code looks like this:

function shareonWall() {

FB.init({appid: '100001125873988', status: true, cookie: true,xfbml:
true});

FB.getLoginStatus(function(response){
....
}


No error, data not posted to my FB wall,
and firebug has the following info under the 'All' tab:
FB.getLoginStatus() called before calling FB.init().

So, it appears the FB code library is executed in alph order, that is,
getLoginStatus (method) is executed first and then
init (method)
....

How can we make the init method to be executed first?

Thanks.
 
K

knowledgenotebook

I highly doubt that they're called in alphabetical order... but who
knows what their script is doing. The message you see in Firebug looks
like it was issued from the Facebook script. I can't help you with the
Facebook specific parts, as I've never used that API before. Don't they
have code examples online somewhere?

BTW, you can ignore Thomas Lahn's pedantic "correction" about domain
parts in generalized URIs, it completely misses the point. Your problem
was that Facebook expected "en_US" in the path, where you wrote "en_us".
There are parts in HTTP URLs which will be handled in a case sensitive
manner by most web servers, so you should always treat them as case
sensitive.

stepfan, yes, my current script uses "en_US" as in
<script src="http://connect.facebook.net/en_US/all.js"></script>

I've also attempted to load the init function with body tag of onload
event trigger, all to no avail.

if Facebook is playing April Fool trick it's time to stop it,
unproductive for all.

thanks.
 
T

Thomas 'PointedEars' Lahn

Stefan said:
BTW, you can ignore Thomas Lahn's pedantic "correction" about domain
parts in generalized URIs, it completely misses the point. Your problem
was that Facebook expected "en_US" in the path, where you wrote "en_us".

Which, AISB, is caused by case-sensitive URL rewrite or server-side
filesystem.
There are parts in HTTP URLs which will be handled in a case sensitive
manner by most web servers, so you should always treat them as case
sensitive.

You cannot draw that conclusion. What you only can say for sure
is that some servers treat some parts of URIs case-sensitively.


PointedEars
 
L

Lasse Reichstein Nielsen

Thomas 'PointedEars' Lahn said:
You cannot draw that conclusion. What you only can say for sure
is that some servers treat some parts of URIs case-sensitively.

Are you arguing that "some" is not the same as "most"?
Do you have data to support that it's not actually "most"?

But still, if only some servers treat some parts of URIs as case
sensitive, I also think it's to be recommended that the client treat
those parts as if they *might* be case-sensitive.

Which was what Stefan Weiss said.

Even if you know that the web server you are accessing is
case-insensitive on the part of the URL that you are creating,
creating different capitalizations of the part is a bad idea,
since it locks you to that web-server. If you pick a consistent
capitalization, you can change the server later without having
to review all you client code.

/L
 
V

VK

if Facebook is playing April Fool trick it's time to stop it,
unproductive for all.

They are not playing fools, they are ones - so it is perpetual. The
API says ( http://developers.facebook.com/docs/reference/javascript/
) : "You must specify a <div> element named fb-root within the
document".
What id doesn't tell you that:
1) no DIV[id="fb-root"] - no init
2) no init - the whole FB library object falls apart with random
cryptic messages ("not initialized" || "not defined" || "bracket
missing" etc.): because the situation that DIV[id="fb-root"] is
missing or not accessible was not considered as an option.
3) FB library is using document.write so initializes before page load
event
4) before page load event it cannot access document.getElementById
because the DOM is not fully accessible so it cannot check if
DIV[id="fb-root"] is presented: so if the library in the document
<head> section, you can place a dozen DIV[id="fb-root"] on your page
and it still will not see it and see outcome (1)(2).
5) Because of (4) FB has to relay on the known quirk in all prominent
browsers when DOM is partially exposed even before page load from the
beginning and up to the point from where the script call is made.
6) Some people are created to be great writers, backers, janitors and
anything else but Javascript programmers. Yet they do believe that
they are Javascript programmers and Facebook takes them to the team
for whatever reason. As they result we having unhappy people doing
something they are not created to do - and unhappy customers forced to
deal with products of such people activity.

Because of (1)-(6) in order to use FB library you need to:

1) place <div id="fb-root"></div> on your page
2) place FB library anywhere *after* that DIV
3) no, you cannot have it in the head section
 
V

VK

6) Some people are created to be great writers, backers, janitors and
anything else but Javascript programmers. Yet they do believe that
they are Javascript programmers and Facebook takes them to the team
for whatever reason. As they result we having unhappy people doing
something they are not created to do - and unhappy customers forced to
deal with products of such people activity.

There is even something darling to see people having no slightest clue
about the job they are doing yet bravely doing it...

http://developers.facebook.com/docs/reference/javascript/
....
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
....


all.js
....
FB.Content._root=c=FB.$('fb-root')
....
$:function(a){return document.getElementById(a);}}
....

Sapienti sat.

If placing FB to the <head> is a must it can be a quirk like:

<script id="fb-root" src="http://connect.facebook.net/en_US/all.js"></
script>

It lets the "library" to init OK - but for for all outcomes of using
script with id in the head instead of div with id in the body - I am
washing my hands.
 
T

Thomas 'PointedEars' Lahn

Stefan said:
I thought that was common knowledge, but here you go:

Apache 69.4%
Microsoft-IIS 19.6%
http://w3techs.com/technologies/overview/web_server/all

Unix 64.1%
Windows 35.9%
http://w3techs.com/technologies/overview/operating_system/all

I can see the reason for your misconception now.
Not that it really matters.

True, your "evidence" does not matter.
It would be enough to know that "some" don't use case folding.

That still does not make your statement about URIs correct.


HTH

PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <rbSdnbw_6-Y2fQjQnZ2dnUVZ8qGdnZ2d@gigane
Seconded. With proper indentation, the problem would have been obvious
at a glance.

That depends on whether the indentation that is actually present
reflects the authors intentions or the code actually present. It is the
difference between these two that is the source of the problem.

Code, preferably without spurious line breaks, can be pasted into a
LOCAL COPY of <http://www.merlyn.demon.co.uk/js-quick.htm> and
systematically indented by pressing a button.

The code which does that does not understand much JavaScript, so (IIRC)
if you have a string containing unmatched braces, you will want to help
by putting the matching braces in end-of-line comment.

A copy of W3 TIDY, from sourceforge, should do better.
 
V

VK

But still, if only some servers treat some parts of URIs as case
sensitive, I also think it's to be recommended that the client treat
those parts as if they *might* be case-sensitive.  

Correction: what parts of URL are we talking about? The case
sensitivity might be exposed *only* for the location.search part.
Anything else is technically possible but is extremely unprofessional.
No one prevents to set a server in the way that
HTTP://wWw.example.com
http://WWW.example.com
http://www.example.com
would redirect to different pages yet show me a moron who would set it
in such way. Oh sorry - a splendid sample is given right in this
thread using FB service...

http://www.ietf.org/rfc/rfc1738.txt
2.1. The main parts of URLs
For resiliency, programs interpreting URLs should treat upper case
letters as equivalent to lower case in scheme names (e.g., allow
"HTTP" as well as "http").

Yes, "should" is not "must" but a a good part of the modern Web
integrity is based on that "should" treated exactly as "must".
 
B

beegee

if Facebook is playing April Fool trick it's time to stop it,
unproductive for all.

thanks.


I believe you must have, as the first tag after the <body>
<div id="fb_root"></div>

all.js looks to this to attach itself to. Highly offtopic but there
ya go.

bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top