Dajax example "Multiply Machine!" not working. Help - ajax

Trying to learn Dajax, so decided to try out examples. But I am stuck with the "multiply" example. I have no clue what is wrong. Below is the code.
ajax.py:(its placed inside 'blog' app)
from dajax.core import Dajax
from dajaxice.core import dajaxice_functions
def multiply(request, a, b):
dajax = Dajax()
result = int(a) * int(b)
dajax.assign('#result','value',str(result))
return dajax.json()
dajaxice_functions.register(multiply)
index.html:
{% load dajaxice_templatetags %}
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Blog</title>
{% dajaxice_js_import %}
<script type="text/javascript" charset="utf-8">
function calculate(){
Dajaxice.blog.multiply(Dajax.process,{'a':$('a').value,'b':$('b').value})
}
</script>
</head>
<body>
<input type="text" name="a" value="5" id="a"> x
<input type="text" name="b" value="6" id="b"> =
<input type="text" name="result" value="" id="result">
<input type="button" name="caculate" value="Let's Multiply!" id="caculate" onclick="calculate()">
</body>
</html>

First of all you should install dajaxice properly. Then, if you are using Dajax you should install Dajax too.
Reading your code seems that dajaxice is correctly installed but you haven't installed Dajax or (at least) you have not linked your dajax-flavoured js.
If you are using Dajax (you are using Dajax) you should choose a framework between Prototype, jQuery, Dojo or mootols and add it to your page, also you need to link the framework.dajax.core.js to your page.
The rest of the installation seems to be already done.

Related

can we call a ftl macro from javascript function

<html lang="en">
<head>
<meta charset="UTF-8">
<title> Java, Spring Boot, FreeMarker</title>
<link href="/css/main.css" rel="stylesheet">
</head>
<script>
function myFunction() {
<#test/>
}
</script>
<body>
<h2>Java, Spring Boot, FreeMarker</h2>
<form action="/search" method="post">
Search : <input type="text" name="firstName" onkeyup="myFunction()" id = "fname">
<input type="submit" value="Submit">
</form>
<div style="background-color:lightblue">
<#macro test>
<#list empList as emp>
<div id="emp-data">
<ul>
<li>${emp}</li>
</ul>
</#list>
</div>
</#macro>
<script src="/js/main.js"></script>
</div>
</body>
When I run this code I am getting some errors on the browser console:
(index):60 Uncaught ReferenceError: myFunction is not defined at HTMLInputElement.onkeyup ((index):60) onkeyup # (index):60 – PCS 1 hour ago
Is it possible in FreeMarker to do something like that?
In a sense you can... but it doesn't do what you apparently believe it does. First all FreeMarker instructions, like <#test/>, are resolved on the server, then later the resulting output runs in the browser. So as far as the browser sees, function myFunction() { ... } contains HTML div-s directly in inside the { ... }, which is invalid JavaScript.

Sagepay Direct 3D Secure Blank Page Issue

I'm trying to implement Omnipay with Sagepay Direct but am really struggling with the 3D Secure bit.
When I post the MD, PaReq and TermUrl to https://test.sagepay.com/mpitools/accesscontroler?action=pareq I just get a blank screen.
These previous SO answers suggest removing spaces from the PaReq field solves the issue, but I don't have any spaces in my data.
SagePay Direct 3DSecure checkout part returning blank page when redirecting out to bank
Sage Pay test server won't load 3D Secure page
The data returned from the Omnipay method $response->getRedirectData() is
"PaReq" => "eJxVUk1TwjAQvfsrGO52mza0lVnCoBxERqcqOuMxpqt0pB8mrRZ/vQkUweTy3svO2+xLcNoVm8EXaZNX5WTIPH84FWe4Wmui+SOpVpPAWzJGvtMgzybDwGcjn7OLmEc8CXnAgmQ0FJjOHuhTYG8krI/HEA7UOmi1lmUjUKrPy8Wd4DwKoxFCT7EgvZiLgPn7HfpuIexlLGVBYqZkRsV2RaZ5pjKrNMJOR1W1ZaO3IgkihAPBVm/EumlqMwaQdW08U1bfmur2dZMrT1Ve+wGGNm/nhvQXIbh6hONF09YhY/27PBNyef308zKLuuXdA0u71DC5DrItj2/uJwiuAjPZkLDxxH4SsgGLx2E85hxhp6Ms3MUEc1P1GGvXYnZycCqgzV5TqQ5zHRhSV1cl2YoA4Q9jRkaJR/dKqdwObtOFbewkhOMgV9cuf9XYSJmLfoecX24DYwnbGzqC4Gqhf1XoP4BF/z7GLxIJvBw="
"MD" => "20150419746483421285"
This is the HTML for the form I'm using
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="https://test.sagepay.com/mpitools/accesscontroler?action=pareq" method="post">
<input name="MD" value="20150419746483421285" type="hidden">
<input name="PaReq" value="eJxVUk1TwjAQvfsrGO52mza0lVnCoBxERqcqOuMxpqt0pB8mrRZ/vQkUweTy3svO2+xLcNoVm8EXaZNX5WTIPH84FWe4Wmui+SOpVpPAWzJGvtMgzybDwGcjn7OLmEc8CXnAgmQ0FJjOHuhTYG8krI/HEA7UOmi1lmUjUKrPy8Wd4DwKoxFCT7EgvZiLgPn7HfpuIexlLGVBYqZkRsV2RaZ5pjKrNMJOR1W1ZaO3IgkihAPBVm/EumlqMwaQdW08U1bfmur2dZMrT1Ve+wGGNm/nhvQXIbh6hONF09YhY/27PBNyef308zKLuuXdA0u71DC5DrItj2/uJwiuAjPZkLDxxH4SsgGLx2E85hxhp6Ms3MUEc1P1GGvXYnZycCqgzV5TqQ5zHRhSV1cl2YoA4Q9jRkaJR/dKqdwObtOFbewkhOMgV9cuf9XYSJmLfoecX24DYwnbGzqC4Gqhf1XoP4BF/z7GLxIJvBw=" type="hidden">
<input name="TermUrl" value="https://www.example.com/payment/auth-return" type="hidden">
<center><p>Please click button below to Authenticate your card</p><input value="Go" type="submit"></center>
</form>
</body>
</html>
Do you know why I'm getting a blank page? Do I need to transform the data in some way before sending it to Sagepay?
I've tried everything I can think of but am getting nowhere.
ok, so it's magically working now....may have been a problem at Sagepay's end?
In case it's useful for someone else, here's my iFrame code...
<iframe src="secure-3d.php?acsURL=<?=$responseUrl?>&PaReq=<?=$responseData['PaReq']?>&MD=<?=$responseData['MD']?>&TermUrl=<?=$responseData['TermUrl']?>" name="secure-3d" id="secure-3d" width="100%" height="500" frameborder="0"></iframe>
...where 'secure-3d.php' is my self-submitting form as below....
<form id="cardToken" name="cardToken" action="<?=$_GET['acsURL']?>" method="post">
<input type="hidden" name="MD" value='<?=str_replace(' ','+',$_GET['MD'])?>' />
<input type="hidden" name="PaReq" value='<?=str_replace(' ','+',$_GET['PaReq'])?>' />
<input type="hidden" name="TermUrl" value='<?=str_replace(' ','+',$_GET['TermUrl'])?>' />
<noscript>
<center><p>Please click button below to Authenticate your card</p><input type="submit" value="Go"/></p></center>
</noscript>
</form>
<script language="Javascript">
var form = document.getElementById("cardToken");
form.submit();
</script>
I just pass the PaReq, MD and TermUrl data through to the form in the querystring, then you need to str_replace spaces to pluses when creating the hidden fields.
That should do it!
If anyone has any ideas on how to make this better, please comment

How to change the language of new Captcha-Recaptcha

Can anyone give me an example about to change to italian ReCaptcha questions and answers?
I found the following code:
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=it" />
But no idea where to put it and all attempts to place it on my contact form failed.
It always speaks english only.
Thanks in advance
Script tags usually go in the head section, between the <head> and </head> tags, or just before the body closing tag, </body>.
However, you also need to add a tag in the form for the ReCaptcha to be show.
This code will display the ReCaptcha in Italian:
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>
</head>
<body>
<form action="?" method="POST">
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
You need to replace the data-sitekey attribute with your own API sitekey.

Grails formRemote tag error

I have been using grails for several weeks now, and have run into this problem when using the g:formRemote tag.
org.grails.taglib.GrailsTagException: [views/inventoryDetails/details.gsp:21] [views/inventoryDetails/details.gsp:21] Tag [formRemote] does not exist. No tag library found for namespace: g
for reference here is the .gsp page
<html>
<head>
<meta name="layout" content="bccmain" />
<title>Details - BCC Virtual Map and Inventory Tracker</title>
<g:javascript library="jquery" />
<link rel="stylesheet" href="${resource(dir: 'css', file: 'details.css')}" type="text/css">
<script>
$(document).ready(function () {
$("#database").addClass("active");
});
</script>
</head>
<body>
<div id ="content">
<g:formRemote name = "detailsUpdateForm" url = "[controller: 'InventoryDetails',action: 'ajaxUpdate']" update="updateBox">
<g:each in ="${details}" var = "d" status = "i">
<g:textField name="details" value = "${d.details}" class = "detailsblock"/>
<g:hiddenField name ="id" value = "${d.id}" />
<g:submitButton name = "submit" value = "Save" />
</g:each>
</g:formRemote>
<div id = "updateBox"></div>
</div>
</body>
</html>
I can't for the life of me figure out why the g:formRemote tag causes a problem, but other tags (run on different pages -- this one won't render) such as g:each will run without a problem. Thanks.
Most likely you are working on a Grails version that does not support "g:formRemote" any more. The formRemote tag and other Ajax related tags have been deprecated. You might want to think about a different approach.

Grails RemoteForm, Ajax doesn't work

I'm new on Grails and I have some troubles with Ajax (so I could have missed something). On my main gsp I want a select box, that, when I click on its options, makes appear another field on the same page to select other things. As the content in the second part is dynamic, I need somme Ajax. Anyway I haven't succeed yet. Here is my code :
main.gsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="layout" content="main" />
<title>Sample title</title>
<g:javascript library="jquery"/>
</head>
<body>
<h1>Selection de l'email</h1>
<div class="dialog">
<g:select name="selectTemplate"
from="${templateCategories}"
value="category"
noSelection="['':'--- choisissez un modèle ---']"
onchange="${remoteFunction(
controller:"email"
action:"printTestTemplate"
update:"listTemplates"
params:'\'category=\'+this.value'
)}"
/>
<div id="listTemplates">RRR</div>
</div>
</body>
</html>
EmailController
def printTestTemplate = {
println params.category //doesn't print anything
println "YEAAAAAAAAAH" //the same
render(view:"formSelectTemplate", model:[templates:EmailTemplate.findByCategory(params.templateCategory)])
}
formSelectTemplate.gsp
<h1>YOUHOUUU !</h1>
I've both tried to call a view or template (by renaming the gsp of course), but nothing worked. Nevertheless I don't understand, I followed the official doc. Notice that the HTML result creates no event on the select box, and that Firebug tells me there is no 404. So I must have missed something in the creation of the box.
select result in HTML :
<select id="selectTemplate" name="selectTemplate">
<option value="Refus">Refus</option>
<option value="Informations complémentaires">Informations complémentaires</option>
</select>
Did you forget comas between the arguments of your remoteFunction call ? like this:
onchange="${remoteFunction(controller:"email",
action:"printTestTemplate",
update:"listTemplates",
params:'\'category=\'+this.value' )}"

Resources