Hello

Now I found a way, to use Ajax with prototype.js but without the utf-8 problems under 4D and Active4D.
I don't send the form variables direct, which would create utf-8.
I use the postBody Option, and generate a escaped string from the form with the function getMyBody().
This creates a request, which is easy to handle with Active4D ore 4D.

<%
$c:=new collection
/*
prototype.js by
http://www.prototypejs.org/
ore a compressed version can be found in protopack_v2.19b.zip
http://groups.google.com/group/prototype-core/files
*/
$c{"prototypePath"}:="/js/lib/prototype.js" // your prototype js-file path
$c{"myPath"}:=current path(*)
$c{"act"}:=""
$c{"reqAct"}:=_form{"act"}
$c{"time"}:=current time
if($c{"reqAct"}="")
        // ------- Head Start----------
        %>
        <?xml version="1.0" encoding="iso-8859-1"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
                "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
        <html xmlns="http://www.w3.org/1999/xhtml";>
        <head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
                <title>Ajax-Test</title>
<script type="text/javascript" src="<%=$c{"prototypePath"}%>"> </ script>
                <script type="text/javascript">
                // <![CDATA[ 
                function ajaxReq(theform,theBlock){
                        $(theform).getMyBody=function(){
                                var objIn=this.serialize(true);
                                var valOut="";
                                  for (var s in objIn){
                                        
valOut+=(valOut==""?"":"&")+s+"="+escape(objIn[s]);
                                  }     
                                return(valOut);
                        };
                
                        $(theform).request({
                                encoding:'iso-8859-1',
                                postBody:$(theform).getMyBody(),
                                onComplete:function(transport){
                                        var myElm=$(theBlock);
                                        $(myElm).update(transport.responseText);
                                }
                        });
                }
                // ]]>
                </script>
        </head>
        <body>
                <h5>Ajax Test</h5>
                <div id="ajaxBlock">
        <%
        // ------- Head End----------           
end if


$c{"usernameAsc"}:=""
$c{"act"}:="step1"
$c{"username"}:=_form{"username"}

$m:=length($c{"username"})
for($n;1;$m)
        $c{"usernameAsc"}+=(ascii($c{"username"}[[$n]])+" ")
end for
a4d.web.dump collection($c)
%>
<form name="form1" id="form1" method="post" action="<%=$c{"myPath"}% >" onsubmit="ajaxReq(this,'ajaxBlock');return false;"> <input type="text" name="username" value="<%=$c{"username"}%>" style="width:240px" />
        <input type="hidden" name="act" value="<%=$c{"act"}%>" />
        <br />
<input type="submit" name="submit" value="ajax test" />
</form>
<%
if($c{"reqAct"}="")
        // ------- Foot Start----------
%>
                </div>
        </body>
        </html>
<%
        // ------- Foot End----------
end if
%>


Regards, Oliver
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to