XMLHttpRequestを使ってCGIインタフェースを実装する

「XMLHttpRequestを使ってCGIインタフェースを実装する」の編集履歴(バックアップ)一覧はこちら

XMLHttpRequestを使ってCGIインタフェースを実装する」(2014/05/07 (水) 16:25:15) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

az-prologのでもサイトでcgiライブラリの実装が沢山あるので、 ここではAjaxを使ってhttpから入出力を行う簡単なサンプルを作ってみます。 http://demo.az-prolog.com/demo/ //test.html <html> <meta http-equiv="Content-Type" content="text/html; charset=Shift-jis"> <script type="text/javascript" src="xmlhttprequest.js"></script> <script type="text/javascript"> function f(){ xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4&&xmlHttp.status==200){ document.getElementById("out1").innerHTML=xmlHttp.responseText; } } str=document.getElementById("in1").value; xmlHttp.open("GET", "echo.cgi?formula="+str, false); xmlHttp.send(null); }; </script> <body> <form> <textarea cols="50" id="in1" rows="1" type="text" placeholder="keyword" value=""></textarea> <input type="button" onclick="f()"/> <div id="out1"></div> </form> </body></html> //echo.cgi //Shift_JISと<html langの間に改行がありますが、これはapacheの仕様によるものなので //無いとエラーになります。 top_call:- get_params(A), html_call(["Content-Type: text/html; charset=Shift_JIS <html lang='ja'><meta charset='Shift_JIS' />",call(ans(A)),"</html>"]). get_params(A):-get_param(formula,A),!. get_params('Hello'). formula(F):-see(F),repeat,read(X),!,seen. ans(A):-write(A),!. ans.

表示オプション

横に並べて表示:
変化行の前後のみ表示: