profile.json into a Javascript Variable

OK, X00, there it is.. )
I think this is not a Vanilla thing, but I#ve searched for solution and found nothing that works... so Youre my hope..
I am making a REAL Chat for Vanilla with Node.js... of course as always with minimum knowledge... )
Cause PHP will not quite work with Node,js (or JS is better in this context) i need to use the profile.json File with Javascript..
How can I put the "http://caba.de/CaBaFoRuM/index.php?p=/profile.json" into an Javascript Variable, so that I can read out the Name of the logged in User??
i tried:
var json = (function () {
var json = null; $.ajax({ 'async': false, 'global': false, 'url': "http://caba.de/CaBaFoRuM/index.php?p=/profile.json", 'dataType': "json", 'success': function (data) { json = data; } }); return json;})();
And:
$.getJSON("http://caba.de/CaBaFoRuM/index.php?p=/profile.json", function(data) {
alert(data.msg);
});
Nothing above is working... the Code is not 100% correct, but you'll get the Idea...
Appreciate any Help, thx...
Comments
I would suspect it doesn't work because you're handling the data outside of the success function, but I don't know much about JS.
The code below should work:
first the person has to already be logged in that context . What is the context this code is running?
If not you have to target a specific user e.g.
http://caba.de/CaBaFoRuM/index.php?p=/profile.json/Klausi
It is cross domain or are you calling it from the same domain becuase you can't request json cross domain with ajax
You have to use JSONP cross domain:
see that
callback=?
that is JSONPhttp://en.wikipedia.org/wiki/JSONP
It may not work still, you will have to set the config option
Garden.AllowJSONP
to TRUE.grep is your friend.
@ R_J: not working... nothing is happening, when I integrate your Code:
I also tried to uncomment the postParseJson line and also tried to add: " async: false," no luck...
Maybe the problem lies in the URL??
@X00:
The Chat is on the same Domain... no cross Domain..

The Chat is stolen from here:
http://socket.io/get-started/chat/
Absolutely fantastic, fast and easy...
I just want to check who is logged in the Forum, then take the Username also to be the Chatname... that simple, but that hard...
I'll tripplecheck all your Code and links... thats just a quick answer.... thanks for helping...
p.s.: working example (Alpha) here:
http://caba.de:3000/
You shouldn't just check for success you should check for failure too.
If people aren't logged in there is no point supplying them the chat in the first place. Serve the chat conditional of being logged in. You needn't do this on the client side.
grep is your friend.
Hmm.. thats what I'm trying to do... to check if the User is logged in and then to enable the chat or to point to the Login... not shure how to do that serverside with node.js...
I finally checked the Console after running the Script:
"NetworkError: 404 Not Found - http://www.caba.de/CaBaFoRuM/index.php?p=/profile.json"
When I put the URL into the Browser, it downloads a "index.php" File with Json Data in it...
This must be it, but no clue how to fix this...
This must be it, but no clue how to fix this...
that is normally json, if you get a json plugin for your browser it will format it nicely in your browser.
I need to see the actual example to see what you are doing wrong.
You don't really want to verify the identity on the client side either, becuase it is no kind of barrier. it is chat basically open any you just want to assign the usernames? Or do you wan t secured system.
grep is your friend.
ARGHH!!! I think, thats all Bull**t what I'm doing...
))
@X00: In long Term I would like to build a secured Chat, but now I'm still learning... so security is no problem at the moment...
I Finally made it half way to work:
1. if I call
http://caba.de/CaBaCHaT/index2.html
it works and I get the Username2. BUT if I call
http://caba.de:3000/
I get an 404 not found error...Here is the complete Index2.html Code:
As written above, its a part of the Socket.io Chat example:
http://socket.io/get-started/chat/
And here my index.js
But as you say, I think I'm all wrong... taught its an easy way to do it...
First I just want an easy way to connect the Chat to the Users... maybe there is another way? Have to reconsider....
p.s.: the originally index.html for the chat is:
I've stumbled upon something like that before, but I cannot remember what the situation was...
But I guess the solution will be to eliminate any "www." in your caba.de links. "www.caba.de" and "caba.de" is not the same and your forum is at "caba.de" and so the user is logged in at caba.de, not www.caba.de
in the context where you are calling the json is there a vanilla cookie. You can only do session operation if the coookie covers that part of the site. You can use the web developer plugin of fire to check, or the normal inspect of firefox and chrome.
grep is your friend.
@Rj: Tried all combinations with and without WWW, HTTP... not working...
It's allways the same... when I call "http://caba.de/CaBaCHaT/index2.html" it works and I get the User name but if I call "http://caba.de:3000" I get an 404 not found error...
But there is no use to call "http://caba.de/CaBaCHaT/index2.html", cause the chat is only working with "http://caba.de:3000"
@x00: Maybe that could be it...
when calling "http://caba.de:3000" i get:

and when I call "http://caba.de/CaBaCHaT/index2.html"
The Chat folder is OUTSIDE the Forum Folder on the same Level... but i tried it also inside, same problems..
Is there a way to call the JSON File over a port?? For example "http://caba.de:3000/CaBaCHaT/index2.html" ??
Or how can I "set" the Cookie??
As you can read I'm now trying ANYTHING...
)))))
YESSSSSS!!!!
:# :#
Found another, WORKING solution...
First Tests are promising... the Usernames are displayed and the speed is enormous!!!!
I'll make some clean up and modifications and then post it for all of you if somebody wants to make a Plugin of it, cause I'm still a noob and have no clue (yet) how to do it... :#
But anyhow a BiiiiiiiiiiiiG THANX to x00 and R_j for helping...
WebSocket is a "new" HTML5 feature and the support is not too good by now: http://caniuse.com/#search=websocket
and there is an implementation with Ratchet (a PHP WebSocket library). If someone is doing a plugin, I would prefer PHP since there is no need for Node.js on a Vanilla server and PHP is already there...
I've seen some implementations with a fallback to flash
My solution is a combination of PHP and Node.js...
I decided to use Node.js, cause it's damn fast!!! Before then I used Ajax Chat and hat performance problems on my small VServer...
My Prealpha working on all major Browsers... with klick sound... yeah..

(only on IE no klick)
What makes that chat fast isn't node.js, it's WebSocket which makes it fast. You can read about it here: http://www.html5rocks.com/en/tutorials/websockets/basics/
You'll need js on the client side to do the live update of the page, but the language of the server is not important.
Don't know about resource consumption, but having a forum using WebSocket instead of AJAX could be quite interesting
Yes, thx for clarification... this is all new to me and aaalll of it ONE big mystery.....


A Forum using Websocket?? Arghh... don't put such funny Ideas in my small head!! I'll might try that......
At least the notifications could be pimped that way