Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-05-2012, 08:42 PM   PM User | #1
3xtrim
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
3xtrim is an unknown quantity at this point
How to show funtion DOM

Hi,
I want o show function results, but I dont know how to do that.

Code:
show = function(t) { console.log(new Date(t).toString()); };
getServertimeFromFacebook = function(cb) {
    ajax("https://api.facebook.com/method/fql.query?query=SELECT+now%28%29+FROM+link_stat+WHERE+url+%3D+%271.2%27&format=json", function(responsetext) {
         var obj = JSON.parse(responsetext);
         var ts = obj[0].anon,
             tms = ts * 1000;
         cb(tms);
    });
};
Please hep me.
3xtrim is offline   Reply With Quote
Old 12-06-2012, 06:24 AM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Code:
function show(t) { alert(new Date(t).toString()); };

getServertimeFromFacebook = function(cb) {
    aGet("https://api.facebook.com/method/fql.query?query=SELECT+now%28%29+FROM+link_stat+WHERE+url+%3D+%271.2%27&format=json", function(responsetext) {
         var obj = JSON.parse(responsetext);
         var ts = obj[0].anon,
             tms = ts * 1000;
         cb(responsetext);
    });
};


getServertimeFromFacebook(show);

function aGet(turl,callback){var XHRt=new XMLHttpRequest;XHRt.onreadystatechange=function(){if(XHRt.readyState==4&&XHRt.status==200){callback(XHRt.responseText,XHRt);}};XHRt.open("GET",turl,true);XHRt.send();return XHRt;}
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 12-06-2012, 09:06 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Of course the debugging alert is just there for testing purposes - you'll need to replace that with some code to actually update the value into the page itself before you go live - unless you want people using the alert to disable JavaScript for your site.

__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-06-2012, 08:23 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by felgall View Post
Of course the debugging alert is just there for testing purposes - you'll need to replace that with some code to actually update the value into the page itself before you go live - unless you want people using the alert to disable JavaScript for your site.

where is that screenshot from? it looks ancient...

none of the 4 current major browsers (ch/ie/sa/ff) i tested have that interface, so i don't think normal people will be disabling scripts from that.

from a browser-ui viewpoint, that's just asinine design: My mom doesn't even know what scripts are, much less what the poor guys did to deserve execution...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 12-06-2012 at 08:27 PM..
rnd me is offline   Reply With Quote
Old 12-06-2012, 08:52 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by rnd me View Post
where is that screenshot from? it looks ancient...

none of the 4 current major browsers (ch/ie/sa/ff) i tested have that interface, so i don't think normal people will be disabling scripts from that.

from a browser-ui viewpoint, that's just asinine design: My mom doesn't even know what scripts are, much less what the poor guys did to deserve execution...
It is MODERN - the browsers that don't display the debugging checkboxes in the dialogs are the ancialt ones.

Prior to 2005 alert confirm and prompt used to be the main ways JavaScript interacted with visitors to the page. Since then forms and being able to update the page itself have replaced those antiquated limited ways of interacting. That means that alert etc are now only useful for quick debugging of code and so extra checkboxes have been added to those dialogs to make them easier to use for debugging.

The prior screenshot is from the CURRENT version of Opera.

Firefox and Chrome both put a similar checkbox into all alerts generated by the page apart from the first one - but instead of disabling JavaScript completely checking that checkbox simply stops any further alert confirm or prompt dialogs from displaying in the page.

Here's a screenshot of an alert from the CURRENT version of Firefox (where the alerts are simply counting with the first alert displaying '1' and this being the second alert).



The alerts generated in the CURRENT version of Chrome are part way between the two with a title bar similar to Opera and content similar to Firefox.

Internet Explorer is the only popular browser that doesn't display these additional checkboxes to aid in debugging (unless they have caught up with the other browsers with version 10 as I don't have a copy of IE10 to test with yet).


ALL of the current browser versions except IE display debugging checkboxes in their alert confirm and prompt dialogs. It is as you say just asinine design on the part of the script author to display these checkboxes to your mom and others that don't know what scripts are - that's why I suggested getting rid of them before other people have access to your page.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 12-06-2012 at 09:05 PM..
felgall is offline   Reply With Quote
Old 12-07-2012, 01:02 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by felgall View Post
It is MODERN - the browsers that don't display the debugging checkboxes in the dialogs are the ancialt ones.

ALL of the current browser versions except IE display debugging checkboxes in their alert confirm and prompt dialogs. It is as you say just asinine design on the part of the script author to display these checkboxes to your mom and others that don't know what scripts are - that's why I suggested getting rid of them before other people have access to your page.
the dialog snooze option does NOT disable JS.

what you originally said was not to use alert() "unless you want people using the alert to disable JavaScript for your site."; a situation only in play for about 1/50 visitors given most web stats. it's an attention grabbing message to be sure, but one that is just not true for the vast majority of us.

while i'm with you 150% as far as avoiding alert(), sell it using UX, not fear.
on mobile, it's actually not as bad, and has an intuitive skin, so lets not drain the bathwater yet.

its use by authors is not the best experience, but the default text on opera is literally ridiculous; no wonder it's stuck at 2%. The fact that the browser itself allows that kind of verbiage to encounter the user is just plain sad. It's as if Opera hasn't even done the self-narrated interaction observer studies. Firefox's is better, though even there, you have the jargon "dialog", a term i'd give my mom 50/50 odds of understanding.


so, yes, don't use prompt(), but don't claim it's usage is as bad as Opera's mis-implementation.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 12-07-2012, 01:48 AM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by rnd me View Post
the dialog snooze option does NOT disable JS.
I agree that simple disabling the debugging dialog messages as Firefox and Chrome do is a better solution than what Opera implemented - Opera did implement their checkbox to turn off JavaScript quite a few years before Firefox and Chrome decided to catch up and overtake Opera's implementation with a more useful one (for debugging purposes but not if misused in live web pages).

Even where the diaalog doesn't disable JavaScript it strill disables any further dialogs - which is exactly what you want if you are using them to debug a loop and have seen enough values to work out what is happening but which is not what you want when validating a form.

With web page that use alerts to display error messages for form field validation the Opera solution of turning off JavaScript if the checkbox is checked means that once they do that they will be able to submit the form and have the server side validation tell them what is wrong. If the checkbox gets checked in Firefox or Chrome then they will not see any further error messages telling them what they need to fix but the JavaScript will still prevent them from submitting the form until they guess what they need to fix. To me the first of these is the better user experience.

Since these dialogs are not intended to be used in live web pages their actual appearancetoday is irrelevant as no one other than the script author should ever see them. It was different back in the Netscape 4 (and earlier) days where they were useful in live pages - then their appearance did matter - and most of the info that they display that you are complaining about were deliberately added to reduce the security issues associated with their misuse.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-07-2012, 10:58 AM   PM User | #8
3xtrim
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
3xtrim is an unknown quantity at this point
Thank you rnd me but I've got ivalid data prompt error.



Do you know whats wrong?
3xtrim is offline   Reply With Quote
Reply

Bookmarks

Tags
dom, function, show

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:39 AM.


Advertisement
Log in to turn off these ads.