[plt-scheme] plt web server question
On Tue, Jun 10, 2008 at 9:14 AM, Chongkai Zhu <czhu at cs.utah.edu> wrote:
> " var url=\"" ,k-url "\";\n"
> " url=url+\"?i=\"+str;\n"
> " url=url+\"&sid=\"+Math.random();\n"
This is the problem. The string here will be XML-quoted, so that '&'
will be turned into '&'. That will mess up the request processing.
You want to put in a XML CDATA element into the Xexpr.
> " xmlHttp.onreadystatechange=stateChanged1;\n"
> " xmlHttp.open(\"GET\",url,true);\n"
> " xmlHttp.send(null);\n"
> "}\n"
> "function stateChanged1()\n"
> "{\n"
> " if (xmlHttp.readyState==4)\n"
> " {\n"
> ;for test
> " alert (xmlHttp.responseText);\n"
> " document.getElementById(\"printtext\").value =
> document.getElementById(\"printtext\").value + \"send succed\";\n"
> ;end for test
> " }\n"
> "}\n"
> "function receive()\n"
> "{\n"
> " xmlHttp=GetXmlHttpObject();\n"
> " if (xmlHttp==null)\n"
> " {\n"
> " alert (\"Your browser does not support AJAX!\");\n"
> " return;\n"
> " }\n"
> " var url=\"" ,k-url "\";\n"
> " url=url+\"&sid=\"+Math.random();\n"
This should be a '?' I believe, not a '&'
Jay
> " xmlHttp.onreadystatechange=stateChanged2;\n"
> " xmlHttp.open(\"GET\",url,true);\n"
> " xmlHttp.send(null);\n"
> "}\n"
> "function stateChanged2()\n"
> "{\n"
> " if (xmlHttp.readyState==4)\n"
> " {\n"
> " document.getElementById(\"printtext\").value =
> document.getElementById(\"printtext\").value + xmlHttp.responseText;\n"
> " receive();\n"
> " }\n"
> "}\n"
> "function GetXmlHttpObject()\n"
> "{\n"
> "var xmlHttp=null;\n"
> "try\n"
> " {\n"
> " // Firefox, Opera 8.0+, Safari\n"
> " xmlHttp=new XMLHttpRequest();\n"
> " }\n"
> "catch (e)\n"
> " {\n"
> " // Internet Explorer\n"
> " try\n"
> " {\n"
> " xmlHttp=new ActiveXObject(\"Msxml2.XMLHTTP\");\n"
> " }\n"
> " catch (e)\n"
> " {\n"
> " xmlHttp=new ActiveXObject(\"Microsoft.XMLHTTP\");\n"
> " }\n"
> " }\n"
> "return xmlHttp;\n"
> "}\n"
> ))
> (body
> (form
> (p "Scheme REPL")
> (p (textarea ([rows "15"]
> [cols "60"]
> [name "printtext"]
> [id "printtext"]
> [readonly "readonly"])
> "Welcome to MzScheme web
> interface\n"))
> (p (textarea ([rows "5"]
> [cols "50"]
> [name "readtext"]
> [id "readtext"])
> "\n")
> (input ([type "button"]
> [value "Send"]
> [onclick "send()"]))))
> (script ([type "text/javascript"])
> "receive();")))))))
> (i (and (exists-binding? 'i bindings)
> (extract-binding/single 'i bindings))))
> (if i
> (begin (write-string i print-pipe-output)
> (newline print-pipe-output)
> (write-string i read-pipe-output)
> (newline read-pipe-output)
> (make-response/full 200
> "Okay"
> (current-seconds)
> #"text/plain"
> (list)
> (list "For test")))
> (make-response/full 200
> "Okay"
> (current-seconds)
> #"text/plain"
> (list)
> (list (begin (sleep 1) (get-print))))))))
>
--
Jay McCarthy <jay.mccarthy at gmail.com>
http://jay.teammccarthy.org