Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use JSON and Perl (HTML::Mason) to create dynamic web page with AJAX?
    primarykey
    data
    text
    <p>I'm some kind of lost with the way i have to deal with Javascript, JSON and Perl and most of the examples are in PHP which is not helpfull for me.</p> <p>I have a page (called main.html) where i have a with data from MySQL and i have an option to delete a row by id.</p> <p>Then i have the Javascript sending the id to page apagar.html which is some kind mess now cos i was trying to deal with JSON, but with GET it works, and what is missing is a refresh after the delete request. But i wanted to introduce JSON in my code and make the page more dinamic but don't know how. </p> <p>And in my apagar.html i have only the code to delete if there is any id in the url.</p> <p>I have read the IBM Series (Mastering Ajax) : <a href="http://www.ibm.com/developerworks/web/library/wa-ajaxintro11.html?S_TACT=105AGX08&amp;S_CMP=EDU" rel="nofollow noreferrer">http://www.ibm.com/developerworks/web/library/wa-ajaxintro11.html?S_TACT=105AGX08&amp;S_CMP=EDU</a></p> <p>Thank you for your help, above is the javascript i'm using:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; var pedido = false; // pedido = request try { pedido = new XMLHttpRequest(); } catch (failed) { pedido = false } if (!pedido) { alert("O seu browser não é suportado."); // Browser not supported } function Eliminar(rid) { // relativo a main.html &amp; apagar.html //alert("SK"); //debug if ( confirm("Deseja realmente eliminar?") ) { var url = "/back/apagar.html?rid=" + escape(rid); /*POST*/ pedido.open("POST", url, true); pedido.onreadystatechange = updatePage; pedido.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); pedido.send( contacto.toJSONString() ); //pedido.open("GET", url, true); //pedido.send(null); } return false; } </code></pre> <p>AND the Mason apagar.html page</p> <pre><code>&lt;%args&gt; $rid =&gt; '' &lt;/%args&gt; &lt;%once&gt; use lib '/var/www/projectox/'; use db::Conexao; #interacao com a DB use DBI; use Apache2::Cookie; #interacao com cookies &lt;/%once&gt; &lt;%init&gt; % # vê se existem cookies my $cookies = Apache2::Cookie-&gt;fetch($r); if(!$cookies){ #sem cookies é enviado para o login $m-&gt;redirect('login.html'); } if($rid) { # vai eliminar os dados pelo valor do id ($rid) #ligacao à DB my $tomada = db::Conexao-&gt;Conexao(); my $sql = $tomada-&gt;prepare("Delete from Contactos where id=?") || die "Impossivel de realizar a operação: $!"; $sql-&gt;execute($rid) || die "Não foi possivel executar: $!"; #desliga da DB $tomada-&gt;disconnect || warn "Não foi possivel terminar a ligação!"; &lt;/%init&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload