r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!Cheyenne] Discussions about the Cheyenne Web Server

amacleod
6-Jan-2011
[9478x2]
I can't get cheyenne to serve to an ajax json request.


I can get it to read the array as a local file but it does not seem 
to work through url request.


I played with content-type: application/json which I read was needed 
but I don't know if I'm on the right track.
For example: 
json data: 
{
  "foo": "The quick brown fox jumps over the lazy dog.",
  "bar": "ABCDEFG",
  "baz": [52, 97]
}

and the js script to fetch the data:

<script>$.getJSON('http://localhost.jsontest.cgi', function(data) 
{
      alert("JSON Data: " + data.foo);
});</script>
GrahamC
6-Jan-2011
[9480]
It works fine for me
I have in my RSP pages

Print json-data
Dockimbel
7-Jan-2011
[9481]
This doesn't look like a valid URL: 'http://localhost.jsontest.cgi'
shadwolf
7-Jan-2011
[9482]
should be http://localhost/jsontest.cgino ?
amacleod
7-Jan-2011
[9483x2]
yes...i just typed it here wrong....thanks
my local script: 
<!DOCTYPE html>
<html>
<head>
  <style>img{ height: 100px; float: left; }</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
	

<script>$.getJSON("http://localhost/jsontest.cgi”, function(data) 
{
      alert("JSON Data: " + data.foo);
});</script>
</body>
</html>

my rebol cgi script:
#!/cgi-bin/rebol.exe -cs %s %s
REBOL [Title: "json test"]
Print {
<html>
<head>
<title></title>

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

</head>
<body>
{
  "foo": "The quick brown fox jumps over the lazy dog.",
  "bar": "ABCDEFG",
  "baz": [52, 97]
}
</body>
</html>
}
PeterWood
7-Jan-2011
[9485]
Alan, I'm logged in to AltME from Ubuntu - so many non-ascii characters 
get displayed incorrectly. In your script the closing double-quote 
after /jsontest.cgi doesn't display properly. Perhaps you could check 
that it really is a double-quote and not a "smart-quote" in the actual 
source.
Dockimbel
7-Jan-2011
[9486]
Amacleod: Your CGI script headers looks very wrong:
- What are those "%s" on the shebang line?

- /cgi-bin/rebol.exe: this doesn't look like a valid filesystem path

- Why the Content-Type header isn't emitted as required by CGI specification?


Maybe you should read again documentation about REBOL CGI usage on 
rebol.com site and also have a look at CGI sample scripts provided 
with Cheyenne source package. Understanding what a shebang line is 
might also help: http://en.wikipedia.org/wiki/Shebang_(Unix)
amacleod
7-Jan-2011
[9487x2]
When i go to the cgi script directly in the browser I get my json 
data displayed. the cgi seems to be working.
- Why the Content-Type header isn't emitted as required by CGI specification?

not sure what this means..
Dockimbel
7-Jan-2011
[9489]
Amacleod: 

while [not understood?][read http://www.rebol.com/docs/core23/rebolcore-13.html#section-13]
GrahamC
7-Jan-2011
[9490]
alan, if you use getJson, you expect to see an application/json header. 
 So, try just $.get instead ....
amacleod
7-Jan-2011
[9491]
That worked. I get the alert but there is an error that  "data"  
(my variable) is undefined.


Can I use use the application/json header and if so what is the syntax...do 
I just replace the the "text/html" string?
Oldes
7-Jan-2011
[9492]
I guess you should print only the JSON data, not html page!
amacleod
7-Jan-2011
[9493x2]
that works, Olds! thanks alot.
only works local though...does not seem to read from remote server
Oldes
7-Jan-2011
[9495]
what kind of server?
amacleod
7-Jan-2011
[9496]
windows
Oldes
7-Jan-2011
[9497]
I mean url
amacleod
7-Jan-2011
[9498x2]
I can see the data when I url the cgi script directly so cgi is working...
bighousefdny.com/cgi-test/jsontest2.r
Oldes
7-Jan-2011
[9500x2]
And what does not work? Btw.. are you setting the content type?
use at beginning:
print "Content-Type: application/json^/"
GrahamC
7-Jan-2011
[9502x5]
No, you can't use remote server .. this is a security feature.
The json data has to be from the same server as the source web page
You need to use JSONP for cross site scripting
Additional Notes:

Due to browser security restrictions, most "Ajax" requests are subject 
to the same origin policy; the request can not successfully retrieve 
data from a different domain, subdomain, or protocol.

Script and JSONP requests are not subject to the same origin policy 
restrictions.
Anyway, we are now off topic for Cheyenne
amacleod
7-Jan-2011
[9507]
Sorry, I thought it might be a cheyenne issue...i'll move to javascript 
group
GrahamC
5-Feb-2011
[9508x2]
Longshot here .. but has anyone written a code formatter for RSP 
pages .. so that it correctly indents HTML, JS, and Rebol all on 
the same page??
there's a php pretty print here http://beta.phpformatter.com/
Kaj
5-Feb-2011
[9510]
That's one reason to write as little code as possible in templates
MikeL
6-Feb-2011
[9511]
Graham:  I am happy using Andrew's ML.r with Cheyenne to implement 
Don't Repeat Yourself on the few pages that I do. <%

 include %ml.inc  ; does [%pop.r %push.r %build-tag.r %ml.r] which 
 can be pre-loaded 
	print ml compose/deep [
		h1 "Heading"
		p {Text paragraph}
		p (now)
	]
%>
Dockimbel
28-Feb-2011
[9512]
Cheyenne's ReBorCon presentation now also available in PDF format. 
The files used for the webapp coding demo have been published too: 
http://cheyenne-server.org/blog.rsp?view=25
Kaj
28-Feb-2011
[9513]
Thanks, Doc!
Claude
28-Feb-2011
[9514]
thanks you ;-)
Dockimbel
3-Mar-2011
[9515x2]
Cheyenne reached a new milestone, as promised during the ReBorCon, 
0.9.20 is out! 

Read the announcement here: http://cheyenne-server.org/blog.rsp?view=26

All the new binaries are built using REBOL 2.7.8, enjoy!
The web site has been updated too, new documentations for Cheyenne 
are pending (will be available tonight).
james_nak
3-Mar-2011
[9517]
Doc, thanks. Can you check the Window's binary links?
Dockimbel
3-Mar-2011
[9518x3]
Broken links, fixing that...
Done.
Thanks James.
james_nak
3-Mar-2011
[9521x2]
Thanks.
Doc, I'm thinking this version fixed my cookie issue with Curecode 
. We'll see. So far it looks great. Merci.
Dockimbel
3-Mar-2011
[9523]
Good to know. You're welcome.
GrahamC
3-Mar-2011
[9524]
Anti-web-scanners configurable engine means what?
Dockimbel
3-Mar-2011
[9525]
Complicate expressions to tell you about a request blocking new feature 
with pattern recognition (see Changelog, look for "block").
GrahamC
3-Mar-2011
[9526x2]
I presume it's okay to start up cheyenne then load up my modified 
http protocol ?
My RSP scripts do a lot of SOAP and REST calls which use my mods